From cffdf8da0cdef3c1733511e1c7ff707cafad26bc Mon Sep 17 00:00:00 2001 From: Brian Deutsch Date: Fri, 8 Nov 2024 16:19:10 -0500 Subject: [PATCH] [web-5519] skip settings sync if typesense config file didn't change (#26159) * test Signed-off-by: Brian Deutsch * test Signed-off-by: Brian Deutsch * order Signed-off-by: Brian Deutsch * config change test Signed-off-by: Brian Deutsch * fix comment Signed-off-by: Brian Deutsch --------- Signed-off-by: Brian Deutsch --- .gitlab-ci.yml | 2 ++ local/bin/js/typesense_sync.cjs | 20 ++++++++++++++------ typesense.config.json | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3da3a62cc8462..7b4a50735dbb2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -281,6 +281,7 @@ typesense_sync_preview:manual: - > TYPESENSE_ADMIN_API_KEY=$(get_secret 'typesense_preview_admin_api_key') TYPESENSE_HOST=$(get_secret 'typesense_preview_host') + TYPESENSE_CONFIG_UPDATED=$(git diff $CI_DEFAULT_BRANCH... --name-only | grep typesense.config.json) yarn run typesense:sync:preview rules: - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' @@ -303,6 +304,7 @@ typesense_sync_live: - > TYPESENSE_ADMIN_API_KEY=$(get_secret 'typesense_prod_admin_api_key') TYPESENSE_HOST=$(get_secret 'typesense_prod_host') + TYPESENSE_CONFIG_UPDATED=$(git diff $CI_DEFAULT_BRANCH... --name-only | grep typesense.config.json) yarn run typesense:sync:production sourcemaps_preview: diff --git a/local/bin/js/typesense_sync.cjs b/local/bin/js/typesense_sync.cjs index 5a8d442feee1f..b0758998510a3 100644 --- a/local/bin/js/typesense_sync.cjs +++ b/local/bin/js/typesense_sync.cjs @@ -2,13 +2,9 @@ const { typesenseSync } = require('typesense-sync'); const { saveSettings } = require('typesense-sync/settings'); const config = require('../../../typesense.config.json'); const fs = require('fs') +const TYPESENSE_CONFIG_UPDATED = process.env.TYPESENSE_CONFIG_UPDATED || false; -saveSettings() - .then(() => index()) - .then(() => console.log('Typesense sync completed')) - .catch(error => console.log('An error occurred', error)) - -const index = async () => { +const indexSite = async () => { const promises = [] // nightly build pipeline syncs all records in Typesense, all others index english records only. @@ -38,3 +34,15 @@ const index = async () => { return await Promise.all(promises) } + +if (TYPESENSE_CONFIG_UPDATED) { + saveSettings() + .then(() => indexSite()) + .then(() => console.log('Typesense sync completed')) + .catch(error => console.log('An error occurred', error)) +} else { + console.log('typesense.config.json unchanged, skipping settings update.') + indexSite() + .then(() => console.log('Typesense sync completed')) + .catch(error => console.log('An error occurred', error)) +} diff --git a/typesense.config.json b/typesense.config.json index 4bec73b080d7d..2bfc22bc5b5c9 100644 --- a/typesense.config.json +++ b/typesense.config.json @@ -6,7 +6,7 @@ "synonyms": [ { "id": "agent", - "synonyms": ["agent", "datadog agent"] + "synonyms": ["agent", "datadog agent", "dd-agent"] }, { "id": "azure",