From 84791563ba359163223ec80ce138d71a6071b5a8 Mon Sep 17 00:00:00 2001 From: Lucas De Morais Date: Fri, 13 Dec 2024 17:51:06 +0100 Subject: [PATCH] fix: cron job --- server/src/services/orama-manager.js | 55 +++++++++++++++------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/server/src/services/orama-manager.js b/server/src/services/orama-manager.js index 0ec34be..872de51 100644 --- a/server/src/services/orama-manager.js +++ b/server/src/services/orama-manager.js @@ -175,6 +175,27 @@ class OramaManager { return { documents_count: offset } } + /* + * Updates the schema of a collection in the Orama Cloud using the OramaCloud SDK. + * Fetches schema from the collection settings if provided, otherwise uses the searchableAttributes from the collection schema. + * @param {Object} collection - Collection object + * */ + async updateSchema(collection) { + const customSchema = this.collectionSettings?.[collection.indexId]?.schema + + const oramaSchema = + customSchema ?? + getSelectedPropsFromObj({ + props: collection.searchableAttributes, + obj: collection.schema + }) + + await this.oramaUpdateSchema({ + indexId: collection.indexId, + schema: oramaSchema + }) + } + /* * Updates the schema of an index in the Orama Cloud using the OramaCloud SDK * @param {string} indexId - Index ID @@ -269,23 +290,11 @@ class OramaManager { return } - const customSchema = this.collectionSettings?.[collection.indexId]?.schema - - const oramaSchema = - customSchema ?? - getSelectedPropsFromObj({ - props: collection.searchableAttributes, - obj: collection.schema - }) - await this.updatingStarted(collection) await this.resetIndex(collection) - await this.oramaUpdateSchema({ - indexId: collection.indexId, - schema: oramaSchema - }) + await this.updateSchema(collection) const { documents_count } = await this.bulkInsert(collection) @@ -310,21 +319,9 @@ class OramaManager { return } - const customSchema = this.collectionSettings?.[collection.indexId]?.schema - - const oramaSchema = - customSchema ?? - getSelectedPropsFromObj({ - props: collection.searchableAttributes, - obj: collection.schema - }) - await this.updatingStarted(collection) - await this.oramaUpdateSchema({ - indexId: collection.indexId, - schema: oramaSchema - }) + await this.updateSchema(collection) await this.oramaDeployIndex(collection) @@ -383,8 +380,14 @@ class OramaManager { await this.resetIndex(collection) + await this.updateSchema(collection) + const { documents_count } = await this.bulkInsert(collection) + if (documents_count > 0) { + await this.oramaDeployIndex(collection) + } + await this.updatingCompleted(collection, documents_count) this.strapi.log.debug(`Scheduled update for ${collection.entity} with indexId ${collection.indexId} completed`)