From 7b588219f914424ff05b9e7b430a64c1f38b08c0 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 27 Jan 2025 08:19:03 +0000 Subject: [PATCH] fix dual writing internal ID conflict --- src/Appwrite/Platform/Workers/UsageDump.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/UsageDump.php b/src/Appwrite/Platform/Workers/UsageDump.php index 0c83a47bfc..6e7c59d200 100644 --- a/src/Appwrite/Platform/Workers/UsageDump.php +++ b/src/Appwrite/Platform/Workers/UsageDump.php @@ -108,6 +108,17 @@ class UsageDump extends Action } } + /** + * Create clone to dual write + * This is required as first request to db + * modifies the document's details like internal ID + * which will conflict in new DB + */ + $clonedProjectDoucments = []; + foreach ($projectDocuments as $document) { + $clonedProjectDoucments[] = new Document($document->getArrayCopy()); + } + $dbForProject->createOrUpdateDocumentsWithIncrease( collection: 'stats', attribute: 'value', @@ -117,7 +128,7 @@ class UsageDump extends Action $dbForLogs->createOrUpdateDocumentsWithIncrease( collection: 'usage', attribute: 'value', - documents: $projectDocuments + documents: $clonedProjectDoucments ); $end = \microtime(true); Console::log('['.DateTime::now().'] Id: '.$project->getId(). ' InternalId: '.$project->getInternalId(). ' Db: '.$project->getAttribute('database').' ReceivedAt: '.$receivedAt. ' Keys: '.$numberOfKeys. ' Time: '.($end - $start).'s');