diff --git a/src/Appwrite/Platform/Workers/Usage.php b/src/Appwrite/Platform/Workers/Usage.php index b3f0516afe..d2aecc31b0 100644 --- a/src/Appwrite/Platform/Workers/Usage.php +++ b/src/Appwrite/Platform/Workers/Usage.php @@ -16,7 +16,7 @@ class Usage extends Action '1h' => 'Y-m-d H:00', '1d' => 'Y-m-d 00:00', 'inf' => '0000-00-00 00:00', - 'inf_d' => 'Y-m-d 00:00', + 'infd' => 'Y-m-d 00:00', ]; protected const INFINITY_PERIOD = '_inf_'; diff --git a/src/Appwrite/Platform/Workers/UsageHook.php b/src/Appwrite/Platform/Workers/UsageHook.php index e99635c1b3..10a2013c4a 100644 --- a/src/Appwrite/Platform/Workers/UsageHook.php +++ b/src/Appwrite/Platform/Workers/UsageHook.php @@ -70,21 +70,29 @@ class UsageHook extends Usage /** * Infinity daily */ - if ('inf_d' === $period) { - $infinity = $dbForProject->getDocument('stats', \md5("{self::INFINITY_PERIOD}{$key}")); + if ('infd' === $period) { + $isInfDaily = array_reduce(["files", "buckets", "users"], function ($carry, $word) use ($key) { + return $carry || str_contains($key, $word); + }, false); + + if (!$isInfDaily) { + continue; + } + + $infinity = $dbForProject->getDocument('stats', \md5(self::INFINITY_PERIOD . $key)); $infinityDaily = $dbForProject->getDocument('stats', $id); - if (empty($infinityDaily) && $infinityDaily->isEmpty()) { + if ($infinityDaily->isEmpty()) { $dbForProject->createDocument('stats', new Document([ '$id' => $id, 'period' => $period, 'time' => $time, 'metric' => $key, - 'value' => $infinity['value'], + 'value' => $infinity['value'] ?? 0, 'region' => App::getEnv('_APP_REGION', 'default'), ])); } else { - $infinityDaily->setAttribute('value', $infinity['value']); + $infinityDaily->setAttribute('value', $infinity['value'] ?? 0); $dbForProject->updateDocument('stats', $infinityDaily->getId(), $infinityDaily); } continue; @@ -120,7 +128,7 @@ class UsageHook extends Usage } } } catch (\Exception $e) { - console::error("[logger] " . " {DateTime::now()} " . " {$projectInternalId} " . " {$e->getMessage()}"); + var_dump($e->getMessage()); } finally { $pools->reclaim(); }