@@ -36,20 +36,19 @@ module.exports = functions.firestore.document(config.typesenseBackfillTriggerDoc
3636 `into Typesense Collection ${ config . typesenseCollectionName } ` +
3737 `on ${ config . typesenseHosts . join ( "," ) } ` ) ;
3838
39- if ( ! validateBackfillRun ( snapshot ) ) {
40- return false ;
41- }
39+ if ( ! validateBackfillRun ( snapshot ) ) {
40+ return false ;
41+ }
4242
4343 const typesense = createTypesenseClient ( ) ;
4444
45- const querySnapshot =
46- await admin . firestore ( ) . collection ( config . firestoreCollectionPath ) ;
47-
45+ const querySnapshot = admin . firestore ( ) . collection ( config . firestoreCollectionPath ) ;
46+
4847 let lastDoc = null ;
4948
5049 do {
51- const queryFotThisBatch = lastDoc ? querySnapshot . startAfter ( lastDoc ) : querySnapshot ;
52- const thisBatch = await queryFotThisBatch . limit ( config . typesenseBackfillBatchSize ) . get ( ) ;
50+ const queryForThisBatch = lastDoc ? querySnapshot . startAfter ( lastDoc ) : querySnapshot ;
51+ const thisBatch = await queryForThisBatch . limit ( config . typesenseBackfillBatchSize ) . get ( ) ;
5352 if ( thisBatch . empty ) {
5453 break ;
5554 }
@@ -65,13 +64,9 @@ module.exports = functions.firestore.document(config.typesenseBackfillTriggerDoc
6564 . import ( currentDocumentsBatch ) ;
6665 functions . logger . info ( `Imported ${ currentDocumentsBatch . length } documents into Typesense` ) ;
6766 } catch ( error ) {
68- if ( error . importResults ) {
69- const failedItems = error . importResults . filter (
70- ( r ) => r . success === false ,
71- ) ;
72- functions . logger . error ( "Import failed with document errors" , failedItems ) ;
73- } else {
74- functions . logger . error ( "Import error" , error ) ;
67+ functions . logger . error ( `Import error in a batch of documents from ${ currentDocumentsBatch [ 0 ] . id } to ${ lastDoc . id } ` , error ) ;
68+ if ( "importResults" in error ) {
69+ logImportErrors ( error . importResults ) ;
7570 }
7671 }
7772
@@ -83,16 +78,8 @@ module.exports = functions.firestore.document(config.typesenseBackfillTriggerDoc
8378 await new Promise ( ( resolve ) => process . nextTick ( resolve ) ) ;
8479 } while ( lastDoc ) ;
8580
86- if ( currentDocumentsBatch . length < config . typesenseBackfillBatchSize ) {
87- break ;
88- }
89- // Recurse on the next process tick, to avoid
90- // issues with the event loop on firebase functions related to resource release
91- await new Promise ( ( resolve ) => process . nextTick ( resolve ) ) ;
92- }
93-
94- functions . logger . info ( "Done backfilling to Typesense from Firestore" ) ;
95- } ) ;
81+ functions . logger . info ( "Done backfilling to Typesense from Firestore" ) ;
82+ } ) ;
9683
9784function logImportErrors ( importResults ) {
9885 importResults . forEach ( ( result ) => {
0 commit comments