From f593498c07100c9e68cada826ac2bf142ca11912 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 27 Jan 2025 07:15:06 +0000 Subject: [PATCH] dual writing --- src/Appwrite/Platform/Workers/UsageDump.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/UsageDump.php b/src/Appwrite/Platform/Workers/UsageDump.php index bb1d605442..4feaf650f8 100644 --- a/src/Appwrite/Platform/Workers/UsageDump.php +++ b/src/Appwrite/Platform/Workers/UsageDump.php @@ -38,6 +38,7 @@ class UsageDump extends Action $this ->inject('message') ->inject('getProjectDB') + ->inject('getLogsDB') ->callback([$this, 'action']); } @@ -48,7 +49,7 @@ class UsageDump extends Action * @throws Exception * @throws \Utopia\Database\Exception */ - public function action(Message $message, callable $getProjectDB): void + public function action(Message $message, callable $getProjectDB, callable $getLogsDB): void { $payload = $message->getPayload() ?? []; if (empty($payload)) { @@ -65,6 +66,7 @@ class UsageDump extends Action } $dbForProject = $getProjectDB($project); + $dbForLogs = $getLogsDB($dbForProject); $projectDocuments = []; $databaseCache = []; $collectionSizeCache = []; @@ -112,6 +114,11 @@ class UsageDump extends Action documents: $projectDocuments ); + $dbForLogs->createOrUpdateDocumentsWithIncrease( + collection: 'stats', + attribute: 'value', + documents: $projectDocuments + ); $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'); }