Skip to content

Commit b39d567

Browse files
authored
Archive logs cleaning (#928)
1 parent f17d048 commit b39d567

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

Helper/ConfigHelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class ConfigHelper
9595
'algoliasearch_advanced/advanced/backend_rendering_allowed_user_agents';
9696
const NON_CASTABLE_ATTRIBUTES = 'algoliasearch_advanced/advanced/non_castable_attributes';
9797
const MAX_RECORD_SIZE_LIMIT = 'algoliasearch_advanced/advanced/max_record_size_limit';
98+
const ARCHIVE_LOG_CLEAR_LIMIT = 'algoliasearch_advanced/advanced/archive_clear_limit';
9899

99100
const SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';
100101

@@ -1112,6 +1113,15 @@ public function getMaxRecordSizeLimit($storeId = null)
11121113
return $this->maxRecordSize;
11131114
}
11141115

1116+
public function getArchiveLogClearLimit($storeId = null)
1117+
{
1118+
return (int) $this->configInterface->getValue(
1119+
self::ARCHIVE_LOG_CLEAR_LIMIT,
1120+
ScopeInterface::SCOPE_STORE,
1121+
$storeId
1122+
);
1123+
}
1124+
11151125
public function getCatalogSearchEngine($storeId = null)
11161126
{
11171127
return $this->configInterface->getValue(self::CATALOG_SEARCH_ENGINE, ScopeInterface::SCOPE_STORE, $storeId);

Model/Queue.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Queue
1919
{
2020
const FULL_REINDEX_TO_REALTIME_JOBS_RATIO = 0.33;
2121
const UNLOCK_STACKED_JOBS_AFTER_MINUTES = 15;
22+
const CLEAR_ARCHIVE_LOGS_AFTER_DAYS = 30;
2223

2324
const SUCCESS_LOG = 'algoliasearch_queue_log.txt';
2425
const ERROR_LOG = 'algoliasearch_queue_errors.log';
@@ -157,6 +158,7 @@ public function runCron($nbJobs = null, $force = false)
157158
}
158159

159160
$this->clearOldLogRecords();
161+
$this->clearOldArchiveRecords();
160162
$this->unlockStackedJobs();
161163

162164
$this->logRecord = [
@@ -588,6 +590,20 @@ private function clearOldLogRecords()
588590
}
589591
}
590592

593+
private function clearOldArchiveRecords()
594+
{
595+
$archiveLogClearLimit = $this->configHelper->getArchiveLogClearLimit();
596+
// Adding a fallback in case this configuration was not set in a consistent way
597+
if ($archiveLogClearLimit < 1) {
598+
$archiveLogClearLimit = self::CLEAR_ARCHIVE_LOGS_AFTER_DAYS;
599+
}
600+
601+
$this->db->delete(
602+
$this->archiveTable,
603+
'created_at < (NOW() - INTERVAL ' . $archiveLogClearLimit . ' DAY)'
604+
);
605+
}
606+
591607
private function unlockStackedJobs()
592608
{
593609
$this->db->update($this->table, [

Setup/UpgradeSchema.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class UpgradeSchema implements UpgradeSchemaInterface
9898
'algoliasearch_advanced/advanced/prevent_backend_rendering' => '0',
9999
'algoliasearch_advanced/advanced/prevent_backend_rendering_display_mode' => 'all',
100100
'algoliasearch_advanced/advanced/backend_rendering_allowed_user_agents' => "Googlebot\nBingbot",
101+
'algoliasearch_advanced/advanced/archive_clear_limit' => '30',
101102
];
102103

103104
private $defaultArrayConfigData = [

etc/adminhtml/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,14 @@
877877
]]>
878878
</comment>
879879
</field>
880+
<field id="archive_clear_limit" translate="label comment" type="text" sortOrder="95" showInDefault="1" showInWebsite="1" showInStore="1">
881+
<label>Archive log clean limit</label>
882+
<comment>
883+
<![CDATA[
884+
(In days - default value is 30) Sets the limit when the oldest records should be cleared from the archive logs (algoliasearch_queue_archive).
885+
]]>
886+
</comment>
887+
</field>
880888
</group>
881889
</section>
882890
<section id="algoliasearch_extra_settings" translate="label" type="text" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">

0 commit comments

Comments
 (0)