Skip to content

Commit 2827caf

Browse files
committed
Updated release code
1 parent f1ecc92 commit 2827caf

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

Helper/ConfigHelper.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ class ConfigHelper
145145
public const ENHANCED_QUEUE_ARCHIVE = 'algoliasearch_advanced/queue/enhanced_archive';
146146
public const NUMBER_OF_ELEMENT_BY_PAGE = 'algoliasearch_advanced/queue/number_of_element_by_page';
147147
public const ARCHIVE_LOG_CLEAR_LIMIT = 'algoliasearch_advanced/queue/archive_clear_limit';
148-
public const MAX_VIRTUAL_REPLICA_COUNT = 50;
149148

150149
/**
151150
* @var Magento\Framework\App\Config\ScopeConfigInterface
@@ -1021,14 +1020,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC
10211020

10221021
$currency = $this->getCurrencyCode($storeId);
10231022
$attributesToAdd = [];
1024-
$defaultVirtualReplicaEnabled = $this->useVirtualReplica($storeId);
1025-
$virtualReplicaCount = 0;
10261023
foreach ($attrs as $key => $attr) {
1027-
if ($virtualReplicaCount < self::MAX_VIRTUAL_REPLICA_COUNT && ($defaultVirtualReplicaEnabled || (isset($attr['virtualReplica']) && $attr['virtualReplica']))){
1028-
$virtualReplica = 1;
1029-
} else {
1030-
$virtualReplica = 0;
1031-
}
10321024
$indexName = false;
10331025
$sortAttribute = false;
10341026
if ($this->isCustomerGroupsEnabled($storeId) && $attr['attribute'] === 'price') {
@@ -1052,7 +1044,6 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC
10521044
$newAttr['attribute'] = $attr['attribute'];
10531045
$newAttr['sort'] = $attr['sort'];
10541046
$newAttr['sortLabel'] = $attr['sortLabel'];
1055-
$newAttr['virtualReplica'] = $virtualReplica;
10561047
if (!array_key_exists('label', $newAttr) && array_key_exists('sortLabel', $newAttr)) {
10571048
$newAttr['label'] = $newAttr['sortLabel'];
10581049
}
@@ -1068,7 +1059,6 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC
10681059
'custom',
10691060
];
10701061
$attributesToAdd[$newAttr['sort']][] = $newAttr;
1071-
$virtualReplicaCount++;
10721062
}
10731063
} elseif ($attr['attribute'] === 'price') {
10741064
$indexName = $originalIndexName . '_' . $attr['attribute'] . '_' . 'default' . '_' . $attr['sort'];
@@ -1078,8 +1068,7 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC
10781068
$sortAttribute = $attr['attribute'];
10791069
}
10801070
if ($indexName && $sortAttribute) {
1081-
$attrs[$key]['name'] = $indexName;
1082-
$attrs[$key]['virtualReplica'] = $virtualReplica;
1071+
$attrs[$key]['name'] = $indexName;
10831072
if (!array_key_exists('label', $attrs[$key]) && array_key_exists('sortLabel', $attrs[$key])) {
10841073
$attrs[$key]['label'] = $attrs[$key]['sortLabel'];
10851074
}
@@ -1094,7 +1083,6 @@ public function getSortingIndices($originalIndexName, $storeId = null, $currentC
10941083
'exact',
10951084
'custom',
10961085
];
1097-
$virtualReplicaCount++;
10981086
}
10991087
}
11001088
$attrsToReturn = [];

Helper/Entity/ProductHelper.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
464464

465465
if ($this->configHelper->isInstantEnabled($storeId)) {
466466
$replicas = array_values(array_map(function ($sortingIndex) {
467-
return [$sortingIndex['name'],$sortingIndex['virtualReplica']];
467+
return $sortingIndex['name'];
468468
}, $sortingIndices));
469469
}
470470

@@ -488,23 +488,24 @@ public function setSettings($indexName, $indexNameTmp, $storeId, $saveToTmpIndic
488488
$this->logger->log('Setting replicas to "' . $indexName . '" index.');
489489
$this->logger->log('Replicas: ' . json_encode($replicas));
490490
$setReplicasTaskId = $this->algoliaHelper->getLastTaskId();
491-
foreach ($sortingIndices as $values) {
492-
if ($values['virtualReplica']) {
491+
if (!$this->configHelper->useVirtualReplica($storeId)) {
492+
foreach ($sortingIndices as $values) {
493+
$replicaName = $values['name'];
494+
$indexSettings['ranking'] = $values['ranking'];
495+
$this->algoliaHelper->setSettings($replicaName, $indexSettings, false, true);
496+
$this->logger->log('Setting settings to "' . $replicaName . '" replica.');
497+
$this->logger->log('Settings: ' . json_encode($indexSettings));
498+
}
499+
} else {
500+
foreach ($sortingIndices as $values) {
493501
$replicaName = $values['name'];
494502
array_unshift($customRanking, $values['ranking'][0]);
495503
$replicaSetting['customRanking'] = $customRanking;
496504
$this->algoliaHelper->setSettings($replicaName, $replicaSetting, false, false);
497505
$this->logger->log('Setting settings to "' . $replicaName . '" replica.');
498506
$this->logger->log('Settings: ' . json_encode($replicaSetting));
499-
} else {
500-
$replicaName = $values['name'];
501-
$indexSettings['ranking'] = $values['ranking'];
502-
$this->algoliaHelper->setSettings($replicaName, $indexSettings, false, true);
503-
$this->logger->log('Setting settings to "' . $replicaName . '" replica.');
504-
$this->logger->log('Settings: ' . json_encode($indexSettings));
505507
}
506508
}
507-
508509
} else {
509510
$this->algoliaHelper->setSettings($indexName, ['replicas' => []]);
510511
$this->logger->log('Removing replicas from "' . $indexName . '" index');
@@ -1546,13 +1547,9 @@ public function handleVirtualReplica($replicas)
15461547
{
15471548
$virtualReplicaArray = [];
15481549
foreach ($replicas as $replica) {
1549-
if ($replica[1]) {
1550-
$replicaArray[] = 'virtual(' . $replica[0] . ')';
1551-
} else {
1552-
$replicaArray[] = $replica[0];
1553-
}
1550+
$virtualReplicaArray[] = 'virtual(' . $replica . ')';
15541551
}
1555-
return $replicaArray;
1552+
return $virtualReplicaArray;
15561553
}
15571554

15581555
/**
@@ -1567,7 +1564,7 @@ public function handlingReplica($indexName, $storeId, $sortingAttribute = false)
15671564
$sortingIndices = $this->configHelper->getSortingIndices($indexName, $storeId, null, $sortingAttribute);
15681565
if ($this->configHelper->isInstantEnabled($storeId)) {
15691566
$replicas = array_values(array_map(function ($sortingIndex) {
1570-
return [$sortingIndex['name'],$sortingIndex['virtualReplica']];
1567+
return $sortingIndex['name'];
15711568
}, $sortingIndices));
15721569

15731570
try {

0 commit comments

Comments
 (0)