From bdecdbd8902a4e364575dc51db3bd69570e06173 Mon Sep 17 00:00:00 2001 From: shimon Date: Mon, 25 Sep 2023 12:51:04 +0300 Subject: [PATCH] pagination --- src/Appwrite/Migration/Version/V20.php | 47 ++++++++++++++------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/Appwrite/Migration/Version/V20.php b/src/Appwrite/Migration/Version/V20.php index a079a63887..28c72ad96b 100644 --- a/src/Appwrite/Migration/Version/V20.php +++ b/src/Appwrite/Migration/Version/V20.php @@ -55,29 +55,32 @@ class V20 extends Migration protected function migrateStatsMetric(string $from, string $to): void { - try { - /** - * Creating inf metric - */ - $sum = $this->projectDB->sum('stats', 'value', [ - Query::equal('metric', [$from]), - Query::equal('period', ['1d']), - Query::greaterThan('value', 0), - ]); + if ( + str_contains($from, 'all') + && str_contains($from, 'total') + ) { + try { + /** + * Creating inf metric + */ + $result = $this->projectDB->findOne('stats', [ + Query::equal('metric', [$from]), + Query::equal('period', ['1d']), + ]); - $id = \md5("null_inf_{$to}"); - - console::log("Creating inf metric to {$to}"); - $this->projectDB->createDocument('stats', new Document([ - '$id' => $id, - 'metric' => $to, - 'period' => 'inf', - 'value' => ($sum + 0), - 'time' => null, - 'region' => 'default', - ])); - } catch (Duplicate $th) { - console::log("Error while creating inf metric: duplicate id {$to} {$id}"); + console::log("Creating inf metric to {$to}"); + $id = \md5("null_inf_{$to}"); + $this->projectDB->createDocument('stats', new Document([ + '$id' => $id, + 'metric' => $to, + 'period' => 'inf', + 'value' => !empty($result) ? $result['value'] : 0, + 'time' => null, + 'region' => 'default', + ])); + } catch (Duplicate $th) { + console::log("Error while creating inf metric: duplicate id {$to} {$id}"); + } } try {