Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit c54aa0d

Browse files
committed
Lucene: detect if the tmp index is currently being modified (last 3 minutes) to avoid multiple indexation tasks loaded concurrently.
1 parent 46bfe38 commit c54aa0d

File tree

8 files changed

+36
-2
lines changed

8 files changed

+36
-2
lines changed

core/src/plugins/index.lucene/class.AjxpLuceneIndexer.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,16 @@ public function applyAction($actionName, $httpVars, $fileVars)
162162
$index = $this->loadIndex($repoId, false);
163163
} catch (Exception $ex) {
164164
AJXP_XMLWriter::header();
165-
if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
165+
if ($this->seemsCurrentlyIndexing($repoId, 3)){
166+
AJXP_XMLWriter::sendMessage($messages["index.lucene.11"], null);
167+
}else if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
166168
AJXP_Controller::applyActionInBackground($repoId, "index", array());
167169
sleep(2);
168170
AJXP_XMLWriter::triggerBgAction("check_index_status", array("repository_id" => $repoId), sprintf($messages["index.lucene.8"], "/"), true, 5);
171+
AJXP_XMLWriter::sendMessage($messages["index.lucene.7"], null);
172+
}else{
173+
AJXP_XMLWriter::sendMessage($messages["index.lucene.12"], null);
169174
}
170-
AJXP_XMLWriter::sendMessage($messages["index.lucene.7"], null);
171175
AJXP_XMLWriter::close();
172176
return null;
173177
}
@@ -700,6 +704,22 @@ protected function loadTemporaryIndex($repositoryId){
700704
return $this->loadIndex($repositoryId, true, null, $tmpIndexPath);
701705
}
702706

707+
/**
708+
* @param String $repositoryId
709+
* @param int $checkInterval
710+
* @return bool
711+
*/
712+
protected function seemsCurrentlyIndexing($repositoryId, $checkInterval){
713+
$tmpIndexPath = $this->getIndexPath($repositoryId)."-PYDIO_TMP";
714+
if(is_dir($tmpIndexPath)){
715+
$mtime = filemtime($tmpIndexPath);
716+
if(time() - $mtime <= 60 * $checkInterval){
717+
return true;
718+
}
719+
}
720+
return false;
721+
}
722+
703723
/**
704724
* @param $repositoryId
705725
*/

core/src/plugins/index.lucene/resources/i18n/de.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
"8" => "Indiziere %s im Hintergrund",
3131
"9" => "Index für aktuelle Arbeitsumgebung nicht gefunden. Bitte starten Sie zuerst die Indizierung!",
3232
"10" => "Indiziere Unterordner im Hintergrund",
33+
"11" => "Workspace seems to be currently indexing, please wait 3 minutes and retry your search.",
34+
"12" => "Workspace is not indexed, try launching indexation manually!"
3335
);

core/src/plugins/index.lucene/resources/i18n/en.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
"8" => "Indexing %s in background",
3131
"9" => "Cannot find index for current workspace! You should trigger the indexation of the data first!",
3232
"10" => "Indexing subfolders in background",
33+
"11" => "Workspace seems to be currently indexing, please wait 3 minutes and retry your search.",
34+
"12" => "Workspace is not indexed, try launching indexation manually!"
3335
);

core/src/plugins/index.lucene/resources/i18n/es.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
"8" => "Indexando %s en segundo plano",
3131
"9" => "No puedo encontrar el índice de la carpeta actual! Debería ejecutar la indexación de los datos primero!",
3232
"10" => "Indexing subfolders in background",
33+
"11" => "Workspace seems to be currently indexing, please wait 3 minutes and retry your search.",
34+
"12" => "Workspace is not indexed, try launching indexation manually!"
3335
);

core/src/plugins/index.lucene/resources/i18n/fr.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
"8" => "Indexation (%s) en arrière-plan.",
3131
"9" => "Impossible de trouver un index pour ce dépôt, vous devrez déclencher l'indexation d'abord !",
3232
"10" => "Indexation des sous-répertoires en arrière-plan",
33+
"11" => "Le workspace est en cours d'indexation, veuillez attendre 3 minutes avant de réessayer.",
34+
"12" => "Le workspace n'est pas indexé pour le moment, veuillez lancer l'indexation manuellement!"
3335
);

core/src/plugins/index.lucene/resources/i18n/it.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
"8" => "Indicizzazione %s in background",
3131
"9" => "Impossibile trovare l'indice per il workspace corrente! È necessario attivare l'indicizzazione dei dati prima!",
3232
"10" => "Indicizzazione sottocartelle in background",
33+
"11" => "Workspace seems to be currently indexing, please wait 3 minutes and retry your search.",
34+
"12" => "Workspace is not indexed, try launching indexation manually!"
3335
);

core/src/plugins/index.lucene/resources/i18n/pt.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
"8" => "A Indexação de %s está a correr em segundo plano",
3131
"9" => "Não foi possível encontrar um Índice para a Área de Trabalho Actual! Deverá ordenar uma Indexação dos ficheiros primeiro!",
3232
"10" => "A Indexar sub-pastas em segundo plano",
33+
"11" => "Workspace seems to be currently indexing, please wait 3 minutes and retry your search.",
34+
"12" => "Workspace is not indexed, try launching indexation manually!"
3335
);

core/src/plugins/index.lucene/resources/i18n/ru.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030
"8" => "Индексирование %s в фоновом режиме",
3131
"9" => "Невозможно найти индекс текущего рабочего пространства! Необходимо сначала включить индексацию!",
3232
"10" => "Индексирование подпапок в фоновом режиме",
33+
"11" => "Workspace seems to be currently indexing, please wait 3 minutes and retry your search.",
34+
"12" => "Workspace is not indexed, try launching indexation manually!"
3335
);

0 commit comments

Comments
 (0)