Skip to content

Commit 7f6c517

Browse files
committed
Use temporary index + swap
1 parent d53301c commit 7f6c517

File tree

3 files changed

+60
-45
lines changed

3 files changed

+60
-45
lines changed

apps/site/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
"@opentelemetry/api-logs": "~0.206.0",
4242
"@opentelemetry/instrumentation": "~0.206.0",
4343
"@opentelemetry/resources": "~1.30.1",
44-
"@orama/core": "^1.2.13",
45-
"@orama/ui": "^1.5.3",
4644
"@opentelemetry/sdk-logs": "~0.206.0",
45+
"@orama/core": "^1.2.14",
46+
"@orama/ui": "^1.5.3",
4747
"@radix-ui/react-tabs": "^1.1.13",
4848
"@radix-ui/react-tooltip": "^1.2.8",
4949
"@tailwindcss/postcss": "~4.1.17",

apps/site/scripts/orama-search/sync-orama-cloud.mjs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { OramaCloud } from '@orama/core';
33
import { getDocuments } from './get-documents.mjs';
44
import { ORAMA_SYNC_BATCH_SIZE } from '../../next.constants.mjs';
55

6-
// The following follows the instructions at https://docs.orama.com/cloud/data-sources/custom-integrations/webhooks
6+
// The following follows the instructions at https://docs.oramasearch.com/docs/cloud/data-sources/rest-APIs/using-rest-apis
77

88
const orama = new OramaCloud({
99
projectId: process.env.NEW_ORAMA_PROJECT_ID || '',
1010
apiKey: process.env.NEW_ORAMA_PRIVATE_API_KEY || '',
1111
});
1212

1313
const datasource = orama.dataSource(process.env.NEW_ORAMA_DATASOURCE_ID || '');
14+
15+
// Create a temporary index to perform the insertions
16+
const temporary = await datasource.createTemporaryIndex();
1417
const documents = await getDocuments();
1518

1619
console.log(`Syncing ${documents.length} documents to Orama Cloud index`);
@@ -27,16 +30,15 @@ const runUpdate = async () => {
2730

2831
console.log(`Sending ${batches.length} batches of ${batchSize} documents`);
2932

33+
// Insert documents batch by batch into the temporary index
3034
for (const batch of batches) {
31-
await datasource.insertDocuments(batch);
35+
await temporary.insertDocuments(batch);
3236
}
37+
38+
// Once all documents are inserted into the temporary index, we swap it with the live one atomically.
39+
await temporary.swap();
3340
};
3441

35-
// Now we proceed to call the APIs in order.
36-
// The previous implementation used to empty the index before inserting new documents
37-
// to remove documents that are no longer in the source.
38-
// The new API from @orama/core might have a different approach for full sync.
39-
// Based on the provided examples, we are now only running the update.
4042
await runUpdate();
4143

4244
console.log('Orama Cloud sync completed successfully!');

pnpm-lock.yaml

Lines changed: 49 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)