Skip to content
Snippets Groups Projects
Commit 7036bb99 authored by Jakob P's avatar Jakob P
Browse files

DIT-512: Cache the list of V3 indexes on acquia_connector-7.x-3.x (#169)

parent bb2a3766
No related branches found
Tags 8.x-2.9
No related merge requests found
......@@ -122,6 +122,13 @@ class AcquiaSearchSolrApi {
* Search indexes list.
*/
public function getIndexes() {
// Get data from cache.
$cid = 'acquia_search.indexes.' . $this->subscription;
if (($cache = cache_get($cid, 'cache')) && $cache->expire > REQUEST_TIME) {
return $cache->data;
}
$query = ['network_id' => $this->subscription];
$nonce = AcquiaSearchSolrCrypt::randomBytes(24);
$config_path = '/v2/index/configure';
......@@ -147,17 +154,28 @@ class AcquiaSearchSolrApi {
$response = drupal_http_request($url, $options);
if ($response->code > 300 || !isset($response->data)) {
$error_message = t("Couldn't connect to Solr. Reason: @reason. Status code: @code. Request: @request", [
$error_message = t("Couldn't connect to Acquia Search v3 to get list of cores. Reason: @reason. Status code: @code. Request: @request", [
'@reason' => isset($response->status_message) ? $response->status_message : '',
'@code' => isset($response->code) ? $response->code : '',
'@request' => isset($response->request) ? $response->request : '',
]);
watchdog('acquia_search_solr', $error_message, [], WATCHDOG_ERROR);
// When API is not reachable, cache results for 1 minute.
$expire = REQUEST_TIME + 60;
cache_set($cid, [], 'cache', $expire);
return [];
}
return $this->processResponse($response->data);
$result = $this->processResponse($response->data);
// Cache will be set in both cases, 1. when search v3 cores are found and
// 2. when there are no search v3 cores but api is reachable.
$expire = REQUEST_TIME + (60 * 60 * 24);
cache_set($cid, $result, 'cache', $expire);
return $result;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment