From 5d8ccf8c9e43198801868972f96feb7e2c665ad4 Mon Sep 17 00:00:00 2001 From: jelveh Date: Tue, 31 Dec 2024 11:21:08 -0800 Subject: [PATCH] Use the correct date formatting in `get_stats` depending on DB engine --- .../src/modules/apps/AppInformationService.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/backend/src/modules/apps/AppInformationService.js b/src/backend/src/modules/apps/AppInformationService.js index 50a347ed3b..08b3db34ac 100644 --- a/src/backend/src/modules/apps/AppInformationService.js +++ b/src/backend/src/modules/apps/AppInformationService.js @@ -374,8 +374,12 @@ class AppInformationService extends BaseService { const [openResult, userResult] = await Promise.all([ db.read(` - SELECT - DATE_FORMAT(FROM_UNIXTIME(ts/1000), '${timeFormat}') as period, + SELECT ` + + db.case({ + mysql: `DATE_FORMAT(FROM_UNIXTIME(ts/1000), '${timeFormat}') as period, `, + sqlite: `STRFTIME('%Y-%m-%d %H', datetime(ts/1000, 'unixepoch'), '${timeFormat}') as period, `, + }) + + ` COUNT(_id) as count FROM app_opens WHERE app_uid = ? @@ -384,8 +388,12 @@ class AppInformationService extends BaseService { ORDER BY period `, queryParams), db.read(` - SELECT - DATE_FORMAT(FROM_UNIXTIME(ts/1000), '${timeFormat}') as period, + SELECT ` + + db.case({ + mysql: `DATE_FORMAT(FROM_UNIXTIME(ts/1000), '${timeFormat}') as period, `, + sqlite: `STRFTIME('%Y-%m-%d %H', datetime(ts/1000, 'unixepoch'), '${timeFormat}') as period, `, + }) + + ` COUNT(DISTINCT user_id) as count FROM app_opens WHERE app_uid = ?