From db0e73b7b92738c2a855820b00a7fd561f27344c Mon Sep 17 00:00:00 2001 From: valentinkolb Date: Wed, 13 Nov 2024 01:42:30 +0100 Subject: [PATCH] fix(analyticsApi): fixed last_30_days_data (2) --- analyticsApi/main.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/analyticsApi/main.go b/analyticsApi/main.go index e578b5b..ddbf6e4 100644 --- a/analyticsApi/main.go +++ b/analyticsApi/main.go @@ -135,23 +135,18 @@ func initPageViewCount(app *pocketbase.PocketBase, e *core.ServeEvent) { FROM analyticsPageViews WHERE path = view.path AND created >= {:startDate} ) AS count, - ( + ( SELECT json_group_array( json_object( - 'date', date, - 'count', daily_count + 'date', strftime('%Y-%m-%d', created), + 'count', COUNT(id) ) ) - FROM ( - SELECT - strftime('%Y-%m-%dT%H:%M:%SZ', created) AS date, - COUNT(id) AS daily_count - FROM analyticsPageViews - WHERE - path = view.path AND - created >= datetime('now', '-30 days') - GROUP BY date - ) AS daily_data + FROM analyticsPageViews + WHERE + path = view.path AND + created >= datetime('now', '-30 days') + GROUP BY strftime('%Y-%m-%d', created) ) AS last_30_days_data FROM analyticsPageViews view