Skip to content

Commit e9242bc

Browse files
committed
MAGE-1138: add use tmp index config
1 parent c47409f commit e9242bc

File tree

5 files changed

+150
-45
lines changed

5 files changed

+150
-45
lines changed

Helper/ConfigHelper.php

Lines changed: 75 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Algolia\AlgoliaSearch\Api\Product\ReplicaManagerInterface;
66
use Algolia\AlgoliaSearch\Helper\Configuration\AutocompleteHelper;
77
use Algolia\AlgoliaSearch\Helper\Configuration\InstantSearchHelper;
8+
use Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper;
89
use Algolia\AlgoliaSearch\Service\AlgoliaConnector;
910
use Algolia\AlgoliaSearch\Service\Serializer;
1011
use Magento\Cookie\Helper\Cookie as CookieHelper;
@@ -42,11 +43,6 @@ class ConfigHelper
4243
public const INDEX_EMPTY_CATEGORIES = 'algoliasearch_categories/categories/index_empty_categories';
4344
public const CATEGORY_SEPARATOR = 'algoliasearch_categories/categories/category_separator';
4445

45-
public const IS_ACTIVE = 'algoliasearch_queue/queue/active';
46-
public const USE_BUILT_IN_CRON = 'algoliasearch_queue/queue/use_built_in_cron';
47-
public const NUMBER_OF_JOB_TO_RUN = 'algoliasearch_queue/queue/number_of_job_to_run';
48-
public const RETRY_LIMIT = 'algoliasearch_queue/queue/number_of_retries';
49-
5046
public const XML_PATH_IMAGE_WIDTH = 'algoliasearch_images/image/width';
5147
public const XML_PATH_IMAGE_HEIGHT = 'algoliasearch_images/image/height';
5248
public const XML_PATH_IMAGE_TYPE = 'algoliasearch_images/image/type';
@@ -156,7 +152,8 @@ public function __construct(
156152
protected GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository,
157153
protected CookieHelper $cookieHelper,
158154
protected AutocompleteHelper $autocompleteConfig,
159-
protected InstantSearchHelper $instantSearchConfig
155+
protected InstantSearchHelper $instantSearchConfig,
156+
protected QueueHelper $queueHelper
160157
)
161158
{}
162159

@@ -384,44 +381,6 @@ public function getNumberOfElementByPage($storeId = null)
384381
return (int)$this->configInterface->getValue(self::NUMBER_OF_ELEMENT_BY_PAGE, ScopeInterface::SCOPE_STORE, $storeId);
385382
}
386383

387-
/**
388-
* @param $storeId
389-
* @return mixed
390-
*/
391-
public function getNumberOfJobToRun($storeId = null)
392-
{
393-
$nbJobs = (int)$this->configInterface->getValue(self::NUMBER_OF_JOB_TO_RUN, ScopeInterface::SCOPE_STORE, $storeId);
394-
395-
return max($nbJobs, 1);
396-
}
397-
398-
/**
399-
* @param $storeId
400-
* @return int
401-
*/
402-
public function getRetryLimit($storeId = null)
403-
{
404-
return (int)$this->configInterface->getValue(self::RETRY_LIMIT, ScopeInterface::SCOPE_STORE, $storeId);
405-
}
406-
407-
/**
408-
* @param $storeId
409-
* @return bool
410-
*/
411-
public function isQueueActive($storeId = null)
412-
{
413-
return $this->configInterface->isSetFlag(self::IS_ACTIVE, ScopeInterface::SCOPE_STORE, $storeId);
414-
}
415-
416-
/**
417-
* @param $storeId
418-
* @return bool
419-
*/
420-
public function useBuiltInCron($storeId = null)
421-
{
422-
return $this->configInterface->isSetFlag(self::USE_BUILT_IN_CRON, ScopeInterface::SCOPE_STORE, $storeId);
423-
}
424-
425384
/**
426385
* @param $storeId
427386
* @return bool
@@ -1715,6 +1674,32 @@ public function isQueueIndexerEnabled(): bool
17151674
*/
17161675
public const LEGACY_USE_VIRTUAL_REPLICA_ENABLED = 'algoliasearch_instant/instant/use_virtual_replica';
17171676

1677+
// --- Indexing Queue --- //
1678+
1679+
/**
1680+
* @deprecated This constant has been moved to a domain specific config helper and will be removed in a future release
1681+
* @see \Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper::IS_ACTIVE
1682+
*/
1683+
public const IS_ACTIVE = QueueHelper::IS_ACTIVE;
1684+
1685+
/**
1686+
* @deprecated This constant has been moved to a domain specific config helper and will be removed in a future release
1687+
* @see \Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper::USE_BUILT_IN_CRON
1688+
*/
1689+
public const USE_BUILT_IN_CRON = QueueHelper::USE_BUILT_IN_CRON;
1690+
1691+
/**
1692+
* @deprecated This constant has been moved to a domain specific config helper and will be removed in a future release
1693+
* @see \Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper::NUMBER_OF_JOB_TO_RUN
1694+
*/
1695+
public const NUMBER_OF_JOB_TO_RUN = QueueHelper::NUMBER_OF_JOB_TO_RUN;
1696+
1697+
/**
1698+
* @deprecated This constant has been moved to a domain specific config helper and will be removed in a future release
1699+
* @see \Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper::RETRY_LIMIT
1700+
*/
1701+
public const RETRY_LIMIT = QueueHelper::RETRY_LIMIT;
1702+
17181703
// --- Indexing Manager --- //
17191704

17201705
/**
@@ -2045,6 +2030,52 @@ public function hidePaginationInInstantSearchPage($storeId = null)
20452030
return $this->instantSearchConfig->shouldHidePagination($storeId);
20462031
}
20472032

2033+
// --- Indexing Queue --- //
2034+
2035+
/**
2036+
* @param $storeId
2037+
* @return bool
2038+
* @deprecated This method has been moved to the Queue config helper and will be removed in a future version
2039+
* @see \Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper::isQueueActive()
2040+
*/
2041+
public function isQueueActive($storeId = null)
2042+
{
2043+
return $this->queueHelper->isQueueActive($storeId);
2044+
}
2045+
2046+
/**
2047+
* @param $storeId
2048+
* @return bool
2049+
* @deprecated This method has been moved to the Queue config helper and will be removed in a future version
2050+
* @see \Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper::useBuiltInCron()
2051+
*/
2052+
public function useBuiltInCron($storeId = null)
2053+
{
2054+
return $this->queueHelper->useBuiltInCron($storeId);
2055+
}
2056+
2057+
/**
2058+
* @param $storeId
2059+
* @return bool
2060+
* @deprecated This method has been moved to the Queue config helper and will be removed in a future version
2061+
* @see \Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper::getNumberOfJobToRun()
2062+
*/
2063+
public function getNumberOfJobToRun($storeId = null)
2064+
{
2065+
return $this->queueHelper->getNumberOfJobToRun($storeId);
2066+
}
2067+
2068+
/**
2069+
* @param $storeId
2070+
* @return bool
2071+
* @deprecated This method has been moved to the Queue config helper and will be removed in a future version
2072+
* @see \Algolia\AlgoliaSearch\Helper\Configuration\QueueHelper::getRetryLimit()
2073+
*/
2074+
public function getRetryLimit($storeId = null)
2075+
{
2076+
return $this->queueHelper->getRetryLimit($storeId);
2077+
}
2078+
20482079
// --- Indexing Manager --- //
20492080

20502081
/**

Helper/Configuration/QueueHelper.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Helper\Configuration;
4+
5+
use Magento\Framework\App\Config\ScopeConfigInterface;
6+
use Magento\Store\Model\ScopeInterface;
7+
8+
class QueueHelper
9+
{
10+
public const IS_ACTIVE = 'algoliasearch_queue/queue/active';
11+
public const USE_BUILT_IN_CRON = 'algoliasearch_queue/queue/use_built_in_cron';
12+
public const NUMBER_OF_JOB_TO_RUN = 'algoliasearch_queue/queue/number_of_job_to_run';
13+
public const RETRY_LIMIT = 'algoliasearch_queue/queue/number_of_retries';
14+
15+
public function __construct(
16+
protected ScopeConfigInterface $configInterface,
17+
) {}
18+
19+
/**
20+
* @param $storeId
21+
* @return bool
22+
*/
23+
public function isQueueActive($storeId = null)
24+
{
25+
return $this->configInterface->isSetFlag(self::IS_ACTIVE, ScopeInterface::SCOPE_STORE, $storeId);
26+
}
27+
28+
/**
29+
* @param $storeId
30+
* @return bool
31+
*/
32+
public function useBuiltInCron($storeId = null)
33+
{
34+
return $this->configInterface->isSetFlag(self::USE_BUILT_IN_CRON, ScopeInterface::SCOPE_STORE, $storeId);
35+
}
36+
37+
/**
38+
* @param $storeId
39+
* @return mixed
40+
*/
41+
public function getNumberOfJobToRun($storeId = null)
42+
{
43+
$nbJobs = (int)$this->configInterface->getValue(self::NUMBER_OF_JOB_TO_RUN, ScopeInterface::SCOPE_STORE, $storeId);
44+
45+
return max($nbJobs, 1);
46+
}
47+
48+
/**
49+
* @param $storeId
50+
* @return int
51+
*/
52+
public function getRetryLimit($storeId = null)
53+
{
54+
return (int)$this->configInterface->getValue(self::RETRY_LIMIT, ScopeInterface::SCOPE_STORE, $storeId);
55+
}
56+
}

Service/Product/IndexBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function buildIndex(int $storeId, ?array $entityIds, ?array $options): vo
102102
$options['page'] ?? 1,
103103
$options['pageSize'] ?? $this->configHelper->getNumberOfElementByPage($storeId),
104104
$entityIds,
105-
$options['useTmpIndex']
105+
$options['useTmpIndex'] ?? false
106106
);
107107

108108
$this->stopEmulation();

etc/adminhtml/system.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,23 @@
10381038
<validate>validate-digits</validate>
10391039
<label>Number of times to retry processing of queued jobs</label>
10401040
<source_model>Algolia\AlgoliaSearch\Model\Source\RetryValues</source_model>
1041+
<comment>
1042+
<![CDATA[
1043+
Defines the number of times that the queue tries to process a job.
1044+
]]>
1045+
</comment>
1046+
<depends>
1047+
<field id="active">1</field>
1048+
</depends>
1049+
</field>
1050+
<field id="use_tmp_index" translate="label comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="0" showInStore="0">
1051+
<label>Use a temporary index for full products reindex</label>
1052+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
1053+
<comment>
1054+
<![CDATA[
1055+
This configuration defines if a temporary index suffixed by <code>_tmp</code> will be used for products full reindex. If you set it to "No", product updates will be sent directly to your production index.
1056+
]]>
1057+
</comment>
10411058
<depends>
10421059
<field id="active">1</field>
10431060
</depends>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<queue>
6767
<use_built_in_cron>0</use_built_in_cron>
6868
<cron_expr>*/5 * * * *</cron_expr>
69+
<use_tmp_index>1</use_tmp_index>
6970
</queue>
7071
</algoliasearch_queue>
7172
<algoliasearch_indexing_manager>

0 commit comments

Comments
 (0)