From 6ed4590e0f2b522188fb85cf1b5e0e9c2e0fd248 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 10 Sep 2025 18:04:35 +0300 Subject: [PATCH] Respect time nulls --- .../Platform/Workers/StatsResources.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index f7ee999a94..daecabf16a 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -434,25 +434,26 @@ class StatsResources extends Action { $message = 'Stats writeDocuments project: ' . $project->getId() . '(' . $project->getSequence() . ')'; - // sort by unique index key reduce locks - usort($this->documents, function($a, $b) { - // metric DESC + /** + * sort by unique index key reduce locks/deadlocks + */ + usort($this->documents, function ($a, $b) { + // Metric DESC $cmp = strcmp($b['metric'], $a['metric']); if ($cmp !== 0) return $cmp; - // period ASC + // Period ASC $cmp = strcmp($a['period'], $b['period']); if ($cmp !== 0) return $cmp; - // time ASC, NULLs first - if ($a['time'] === null && $b['time'] === null) return 0; - if ($a['time'] === null) return -1; + // Time ASC, NULLs first + if ($a['time'] === null) return ($b['time'] === null) ? 0 : -1; if ($b['time'] === null) return 1; return strcmp($a['time'], $b['time']); }); -var_dump($this->documents); + var_dump($this->documents); try { $dbForLogs->createOrUpdateDocuments( 'stats',