From 83a126c5319bdafe715394499e727a4468f9ca52 Mon Sep 17 00:00:00 2001 From: kiminkim724 Date: Tue, 20 Aug 2024 20:08:55 -0400 Subject: [PATCH] Check when converting documents during collection alias backfill --- functions/src/search/SearchIndexer.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/functions/src/search/SearchIndexer.ts b/functions/src/search/SearchIndexer.ts index ffeb21e7c..7fc7305ff 100644 --- a/functions/src/search/SearchIndexer.ts +++ b/functions/src/search/SearchIndexer.ts @@ -85,6 +85,7 @@ export class SearchIndexer { if (!this.collection) { const collection = this.client.collections(this.collectionName) const exists = await collection.exists() + console.log("Collection exists", exists) if (!exists) await this.createCollection() this.collection = collection } @@ -104,7 +105,15 @@ export class SearchIndexer { currentBatch++ if (numBatches && currentBatch > numBatches) return - const docs = batch.map(d => convert(d.data())) + const docs = batch.reduce((acc, d) => { + try { + const doc = convert(d.data()) + acc.push(doc) + } catch (error: any) { + console.error(`Failed to convert document: ${error.message}`) + } + return acc + }, [] as any[]) const collection = await this.getCollection() try { await collection.documents().import(docs, { action: "upsert" }) @@ -131,7 +140,14 @@ export class SearchIndexer { private async upgradeAlias() { const { alias } = this.config + console.log("Upgrading alias", alias) const obsoleteCollection = await this.getCurrentCollectionName() + console.log( + "Upgrading collection", + obsoleteCollection, + "to", + this.collectionName + ) await this.client .aliases() .upsert(alias, { collection_name: this.collectionName })