Today I experienced multiple events for a firestore create trigger.
According to the firebase documentation here:
... we plan to guarantee "at least once" delivery.
My question is: Are you also working on a "max one trigger on create"? Or should I rely on callable functions for such a use-case?
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/e40861fa-55be-4f13-9cfd-21417a0d97ca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/1546f5c2-2b5c-4fba-ae15-69b4087a177a%40googlegroups.com.
async function isDuplicateCreateOrUpdateEvent(change: Change<FirebaseFirestore.DocumentSnapshot>, context: EventContext): Promise<boolean> { try { const firestoreEventType: 'create' | 'update' | 'delete' = checkEventType(change); logger.debug(`isDuplicateCreateOrUpdateEvent called, analyzing event from ${change.after.ref}, eventType: ${firestoreEventType}`); if (firestoreEventType === 'delete') { // We don't worry about multiple delete events. Just mark the helper doc, with deleted: true await afs.doc(`utils/${change.before.id}`).set({deleted: true}, {merge: true}); return false; } const t = await afs.runTransaction(async (transaciton: FirebaseFirestore.Transaction) => { logger.debug(`Transaction running inside isDuplicateCreateOrUpdateEvent`); // Start by extracting the utils document const metaDocRef = afs.doc(`utils/${change.after.id}`); const metaDoc = await transaciton.get(metaDocRef); const lastEventId = metaDoc.data()[`${firestoreEventType}_lastEventId`]; if (lastEventId === context.eventId) { // If lastEventId === process.env.eventId, we processed this trigger before, i.e. a duplicate event return true; } // If we reach here, it's not a duplicate event. Save the lastEventId, to prevent duplicate future triggers await transaciton.set(metaDocRef, {[`${firestoreEventType}_lastEventId`]: context.eventId}, {merge: true}); return false; }); return t; } catch (error) { // When will we execute here? Hmm.. If the transaction fails, is this gonna emit? // Read documentation here: https://firebase.google.com/docs/firestore/manage-data/transactions logger.error(`isDuplicateCreateOrUpdateEvent failed with error: ${error.message}`); throw error; } }