From 9f3dd54198560c07b9a6b8c13d7396e9598ad6b3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 25 Aug 2022 18:27:55 +1200 Subject: [PATCH] Fix merge clobber --- src/Appwrite/Usage/Calculators/Database.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Appwrite/Usage/Calculators/Database.php b/src/Appwrite/Usage/Calculators/Database.php index 875af7f311..1112324971 100644 --- a/src/Appwrite/Usage/Calculators/Database.php +++ b/src/Appwrite/Usage/Calculators/Database.php @@ -74,6 +74,16 @@ class Database extends Calculator */ protected function createOrUpdateMetric(string $projectId, string $metric, string $period, int $time, int $value): void { + $date = new \DateTime(); + if ($period === '30m') { + $minutes = $date->format('i') >= '30' ? "30" : "00"; + $time = $date->format('Y-m-d H:' . $minutes . ':00'); + } elseif ($period === '1d') { + $time = $date->format('Y-m-d 00:00:00'); + } else { + throw new Exception("Period type not found", 500); + } + $id = \md5("{$time}_{$period}_{$metric}"); $this->database->setNamespace('_' . $projectId);