Skip to content

Commit 7f1261c

Browse files
committed
a way for customers to change timeout values for Algolia PHP
1 parent 0247b4c commit 7f1261c

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

Helper/AlgoliaHelper.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Algolia\AlgoliaSearch\Response\AbstractResponse;
77
use Algolia\AlgoliaSearch\Response\BatchIndexingResponse;
88
use Algolia\AlgoliaSearch\Response\MultiResponse;
9+
use Algolia\AlgoliaSearch\Config\SearchConfig;
910
use Algolia\AlgoliaSearch\SearchClient;
1011
use Algolia\AlgoliaSearch\SearchIndex;
1112
use Algolia\AlgoliaSearch\Support\UserAgent;
@@ -89,10 +90,11 @@ public function getRequest()
8990
public function resetCredentialsFromConfig()
9091
{
9192
if ($this->config->getApplicationID() && $this->config->getAPIKey()) {
92-
$this->client = SearchClient::create(
93-
$this->config->getApplicationID(),
94-
$this->config->getAPIKey()
95-
);
93+
$config = SearchConfig::create($this->config->getApplicationID(), $this->config->getAPIKey());
94+
$config->setConnectTimeout($this->config->getConnectionTimeout());
95+
$config->setReadTimeout($this->config->getReadTimeout());
96+
$config->setWriteTimeout($this->config->getWriteTimeout());
97+
$this->client = SearchClient::createWithConfig($config);
9698
}
9799
}
98100

Helper/ConfigHelper.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class ConfigHelper
100100
'algoliasearch_advanced/advanced/backend_rendering_allowed_user_agents';
101101
public const NON_CASTABLE_ATTRIBUTES = 'algoliasearch_advanced/advanced/non_castable_attributes';
102102
public const MAX_RECORD_SIZE_LIMIT = 'algoliasearch_advanced/advanced/max_record_size_limit';
103+
public const CONNECTION_TIMEOUT = 'algoliasearch_advanced/advanced/connection_timeout';
104+
public const READ_TIMEOUT = 'algoliasearch_advanced/advanced/read_timeout';
105+
public const WRITE_TIMEOUT = 'algoliasearch_advanced/advanced/write_timeout';
103106

104107
public const SHOW_OUT_OF_STOCK = 'cataloginventory/options/show_out_of_stock';
105108

@@ -1174,6 +1177,33 @@ public function getIndexPrefix($storeId = null)
11741177
return $this->configInterface->getValue(self::INDEX_PREFIX, ScopeInterface::SCOPE_STORE, $storeId);
11751178
}
11761179

1180+
/**
1181+
* @param $storeId
1182+
* @return mixed'
1183+
*/
1184+
public function getConnectionTimeout($storeId = null)
1185+
{
1186+
return $this->configInterface->getValue(self::CONNECTION_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
1187+
}
1188+
1189+
/**
1190+
* @param $storeId
1191+
* @return mixed'
1192+
*/
1193+
public function getReadTimeout($storeId = null)
1194+
{
1195+
return $this->configInterface->getValue(self::READ_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
1196+
}
1197+
1198+
/**
1199+
* @param $storeId
1200+
* @return mixed'
1201+
*/
1202+
public function getWriteTimeout($storeId = null)
1203+
{
1204+
return $this->configInterface->getValue(self::WRITE_TIMEOUT, ScopeInterface::SCOPE_STORE, $storeId);
1205+
}
1206+
11771207
/**
11781208
* @param $storeId
11791209
* @return array|bool|float|int|mixed|string

etc/adminhtml/system.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,15 @@
12591259
If your Algolia plan allows a higher record size limit, you can customize the record size limit.]]>
12601260
</comment>
12611261
</field>
1262+
<field id="connection_timeout" translate="label comment" type="text" sortOrder="100" showInDefault="1">
1263+
<label>Connection Timeout (In Seconds)</label>
1264+
</field>
1265+
<field id="read_timeout" translate="label comment" type="text" sortOrder="105" showInDefault="1">
1266+
<label>Read Timeout (In Seconds)</label>
1267+
</field>
1268+
<field id="write_timeout" translate="label comment" type="text" sortOrder="110" showInDefault="1">
1269+
<label>Write Timeout (In Seconds)</label>
1270+
</field>
12621271
</group>
12631272
<group id="queue" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
12641273
<label>Indexing Queue</label>

etc/config.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
<algoliasearch_advanced>
8282
<advanced>
8383
<max_record_size_limit>10000</max_record_size_limit>
84+
<connection_timeout>2</connection_timeout>
85+
<read_timeout>30</read_timeout>
86+
<write_timeout>30</write_timeout>
8487
</advanced>
8588
<queue>
8689
<number_of_element_by_page>300</number_of_element_by_page>

0 commit comments

Comments
 (0)