Rank 2: Process
Hi, this a function in dart that subtract a 1 from the LMMS attribute for 6000 documents then update every document with the new subtracted value, the issue is, it takes so long (11 minutes)😭
var response = await database.listDocuments(
databaseId: databaseId,
collectionId: collectionId,
queries: [Query.limit(6000)]);
var documents = response.documents;
try {
for (var doc = 0; doc < documents.length; doc++) {
String documentId = documents[doc].$id;
final data = documents[doc].data;
// Subtract 1 from LMMS first
int LMMS = data['LMMS'] - 1;
// Update the document with the initially subtracted LMMS
await database.updateDocument(
databaseId: databaseId,
collectionId: collectionId,
documentId: documentId,
data: {'LMMS': LMMS});
}
return context.res.send(200);
} catch (e) {
print('Error updating document: $e');
return context.res.send(401);
}
Could any one help me make it faster.