Skip to content

Commit

Permalink
fix: cron job
Browse files Browse the repository at this point in the history
  • Loading branch information
raiindev committed Dec 13, 2024
1 parent f404e88 commit 8479156
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions server/src/services/orama-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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`)
Expand Down

0 comments on commit 8479156

Please sign in to comment.