GCP Cloud Functions Timeout guide When Using Firestore Transactions
I'm a bit lost with I'm maintaining legacy code that I've looked through the documentation and I'm still confused about Quick question that's been bugging me - I've been banging my head against this for hours. I'm working with a frustrating scenario where my Cloud Function is timing out when trying to perform a Firestore transaction. I'm using Node.js 14 and the Firebase Admin SDK version 9.11.0. My function is supposed to update multiple documents atomically, but it often exceeds the 60-second execution limit, especially under load. I've tried increasing the timeout setting for the function in the GCP console, but it doesn't seem to impact the transaction time. Here's the code snippet I'm using: ```javascript const admin = require('firebase-admin'); admin.initializeApp(); exports.updateDocuments = async (req, res) => { const db = admin.firestore(); const documentRef = db.collection('myCollection'); const batch = db.batch(); const documentsToUpdate = ['doc1', 'doc2', 'doc3']; documentsToUpdate.forEach(docId => { const docRef = documentRef.doc(docId); batch.update(docRef, { updatedAt: admin.firestore.FieldValue.serverTimestamp() }); }); try { await batch.commit(); res.status(200).send('Documents updated successfully.'); } catch (behavior) { console.behavior('behavior updating documents:', behavior); res.status(500).send('Internal server behavior.'); } }; ``` When I deploy this function and trigger it, I often see the `Function execution took too long` behavior. I've also tried splitting the updates into smaller batches, but this hasn't resolved the timeout scenario. Is there a better way to handle this, or am I missing something in terms of configuration that could help optimize the transaction performance? Thanks, I really appreciate it! Cheers for any assistance!