Skip to content

Commit 44db1d0

Browse files
SultanICQDavid Garcia Latorrergomezcasas
authored
Don't create elasticsearch indexes on prod (CodelyTV#225)
* Little optimization. Save cpu cycles on prod environment. * Update src/Shared/Infrastructure/Elasticsearch/ElasticsearchClientFactory.php Co-authored-by: David Garcia Latorre <dgarcia@seocom.agency> Co-authored-by: Rafa Gómez <rgomezcasas@gmail.com>
1 parent f653669 commit 44db1d0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/Shared/Infrastructure/Elasticsearch/ElasticsearchClientFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ private function generateIndexIfNotExists(
3030
string $schemasFolder,
3131
string $environment
3232
): void {
33+
if ('prod' !== $environment) {
34+
return;
35+
}
36+
3337
$indexes = Utils::filesIn($schemasFolder, '.json');
3438

3539
foreach ($indexes as $index) {
3640
$indexName = str_replace('.json', '', sprintf('%s_%s', $indexPrefix, $index));
3741

38-
if ('prod' !== $environment && !$this->indexExists($client, $indexName)) {
42+
if (!$this->indexExists($client, $indexName)) {
3943
$indexBody = Utils::jsonDecode(file_get_contents("$schemasFolder/$index"));
4044

4145
$client->indices()->create(['index' => $indexName, 'body' => $indexBody]);

0 commit comments

Comments
 (0)