Skip to content

Commit

Permalink
[web-5519] skip settings sync if typesense config file didn't change (#…
Browse files Browse the repository at this point in the history
…26159)

* test

Signed-off-by: Brian Deutsch <[email protected]>

* test

Signed-off-by: Brian Deutsch <[email protected]>

* order

Signed-off-by: Brian Deutsch <[email protected]>

* config change test

Signed-off-by: Brian Deutsch <[email protected]>

* fix comment

Signed-off-by: Brian Deutsch <[email protected]>

---------

Signed-off-by: Brian Deutsch <[email protected]>
  • Loading branch information
bgdeutsch authored Nov 8, 2024
1 parent 3b5b8ff commit cffdf8d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand Down
20 changes: 14 additions & 6 deletions local/bin/js/typesense_sync.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion typesense.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"synonyms": [
{
"id": "agent",
"synonyms": ["agent", "datadog agent"]
"synonyms": ["agent", "datadog agent", "dd-agent"]
},
{
"id": "azure",
Expand Down

0 comments on commit cffdf8d

Please sign in to comment.