From 15292a38f56fd76f96ae603c310f019f214833f6 Mon Sep 17 00:00:00 2001 From: Richard BAYET Date: Tue, 10 Dec 2024 19:57:30 +0100 Subject: [PATCH] [Core] Setting to customize time before an index becomes ghost --- .../Helper/IndexSettings.php | 10 ++++++++++ .../etc/adminhtml/system.xml | 15 ++++++++++----- src/module-elasticsuite-core/etc/config.xml | 1 + src/module-elasticsuite-core/i18n/en_US.csv | 2 ++ src/module-elasticsuite-core/i18n/fr_FR.csv | 2 ++ .../Model/IndexStatusProvider.php | 2 +- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/module-elasticsuite-core/Helper/IndexSettings.php b/src/module-elasticsuite-core/Helper/IndexSettings.php index a7e525c7e..b5ae2527b 100644 --- a/src/module-elasticsuite-core/Helper/IndexSettings.php +++ b/src/module-elasticsuite-core/Helper/IndexSettings.php @@ -300,6 +300,16 @@ public function getNumberOfReplicasPerIndex(string $indexIdentifier): int return (int) $this->getIndicesSettingsConfigParam('number_of_replicas'); } + /** + * Returns the time elapsed (in seconds) since its creation after which a non-live index is to be considered ghost. + * + * @return int + */ + public function getTimeBeforeGhost(): int + { + return (int) $this->getIndicesSettingsConfigParam('ghost_timeout'); + } + /** * Get number the batch indexing size from the configuration. * diff --git a/src/module-elasticsuite-core/etc/adminhtml/system.xml b/src/module-elasticsuite-core/etc/adminhtml/system.xml index 3b67fca92..9b0d4b8b7 100644 --- a/src/module-elasticsuite-core/etc/adminhtml/system.xml +++ b/src/module-elasticsuite-core/etc/adminhtml/system.xml @@ -90,25 +90,30 @@ - + - + - + validate-number - + validate-number - + Smile\ElasticsuiteCore\Block\Adminhtml\Form\Field\IndicesSettings\DynamicField Magento\Config\Model\Config\Backend\Serialized\ArraySerialized + + + + integer validate-greater-than-zero validate-number-range number-range-3600-172800 + diff --git a/src/module-elasticsuite-core/etc/config.xml b/src/module-elasticsuite-core/etc/config.xml index 5e65c1d64..cef8eaa21 100644 --- a/src/module-elasticsuite-core/etc/config.xml +++ b/src/module-elasticsuite-core/etc/config.xml @@ -34,6 +34,7 @@ 1 0 1000 + 172800 diff --git a/src/module-elasticsuite-core/i18n/en_US.csv b/src/module-elasticsuite-core/i18n/en_US.csv index 8ca7cd621..3b249391f 100644 --- a/src/module-elasticsuite-core/i18n/en_US.csv +++ b/src/module-elasticsuite-core/i18n/en_US.csv @@ -128,3 +128,5 @@ Autocomplete,Autocomplete "Custom stemmer","Custom stemmer" "In the list ""[default]"" indicates the stemmer used by Elasticsuite by default for the language, while ""[recommended]"" indicates the stemmer is the one or one of those recommended for that language by Elasticsearch in its online documentation. Those can differ, hence this configuration parameter.","In the list ""[default]"" indicates the stemmer used by Elasticsuite by default for the language, while ""[recommended]"" indicates the stemmer is the one or one of those recommended for that language by Elasticsearch in its online documentation. Those can differ, hence this configuration parameter." "Please select a stemmer for the store","Please select a stemmer for the store" +"Time for an index to be considered Ghost (in seconds)","Time for an index to be considered Ghost (in seconds)" +"Elasticsuite derelict indices resulting from a failed full reindex are considered ghost after this amount of time (in seconds) has elapsed since their creation. You can reduce this amount of time to speed up ghost indices cleanup, but take care to add a safety on top of the maximum reindexing duration of the more complex index of your platform (usually a catalog_product/product search index). Defaults to 172,800 seconds (2 days), minimum value: 3600 (1 hour).","Elasticsuite derelict indices resulting from a failed full reindex are considered ghost after this amount of time (in seconds) has elapsed since their creation. You can reduce this amount of time to speed up ghost indices cleanup, but take care to add a safety on top of the maximum reindexing duration of the more complex index of your platform (usually a catalog_product/product search index). Defaults to 172,800 seconds (2 days), minimum value: 3600 (1 hour)." diff --git a/src/module-elasticsuite-core/i18n/fr_FR.csv b/src/module-elasticsuite-core/i18n/fr_FR.csv index e26e9f71e..d5dde3dae 100644 --- a/src/module-elasticsuite-core/i18n/fr_FR.csv +++ b/src/module-elasticsuite-core/i18n/fr_FR.csv @@ -128,3 +128,5 @@ General,Général "Custom stemmer","Stemmer spécifique" "In the list ""[default]"" indicates the stemmer used by Elasticsuite by default for the language, while ""[recommended]"" indicates the stemmer is the one or one of those recommended for that language by Elasticsearch in its online documentation. Those can differ, hence this configuration parameter.","Dans la liste, ""[default]"" indique le stemmer utilisé par défaut par Elasticsuite pour la langue, tandis que ""[recommended]"" indique que le stemmer est celui ou l'un de deux recommendés pour cette langue par Elasticsearch dans sa documentation en ligne. Ceux-ci peuvent différer, d'où l'existence de ce paramètre de configuration." "Please select a stemmer for the store","Veuillez sélectionner un stemmer pour le magasin" +"Time for an index to be considered Ghost (in seconds)","Temps avant qu'un index soit considéré Fantôme (en secondes)" +"Elasticsuite derelict indices resulting from a failed full reindex are considered ghost after this amount of time (in seconds) has elapsed since their creation. You can reduce this amount of time to speed up ghost indices cleanup, but take care to add a safety on top of the maximum reindexing duration of the more complex index of your platform (usually a catalog_product/product search index). Defaults to 172,800 seconds (2 days), minimum value: 3600 (1 hour).","Les index Elasticsuite résultant de l'échec d'une ré-indexation complète sont considérés comme fantômes après que cette période de temps (en secondes) s'est écoulée depuis leur création. Vous pouvez réduire cette période de temps pour accélérer la suppression des index fantômes, mais prenez soin d'ajouter une période de sécurité au temps de réindexation maximum de l'index le plus complexe de votre plateforme (généralement un index catalog_product/de recherche produits). Valeur par défaut: 172 800 secondes (2 jours), valeur minimum: 3600 (1 heure)." diff --git a/src/module-elasticsuite-indices/Model/IndexStatusProvider.php b/src/module-elasticsuite-indices/Model/IndexStatusProvider.php index 6ca065186..10a828127 100644 --- a/src/module-elasticsuite-indices/Model/IndexStatusProvider.php +++ b/src/module-elasticsuite-indices/Model/IndexStatusProvider.php @@ -160,7 +160,7 @@ private function isExternal(string $indexName): bool private function isGhost($indexDate): bool { try { - return (new Zend_Date())->sub($indexDate)->getTimestamp() / self::SECONDS_IN_DAY >= self::NUMBER_DAYS_AFTER_INDEX_IS_GHOST; + return (new Zend_Date())->sub($indexDate)->getTimestamp() >= $this->indexSettingsHelper->getTimeBeforeGhost(); } catch (Zend_Date_Exception $e) { return false; }