From af3fc7daa8a6d045f0515531e3eb66063f0218d4 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Tue, 3 May 2022 20:38:58 +0200 Subject: [PATCH] Add comment about countR30UsersSQL and countR30UsersV2SQL; fix test --- userapi/storage/postgres/stats_table.go | 4 ++++ userapi/storage/sqlite3/stats_table.go | 8 ++++++++ userapi/storage/tables/stats_table_test.go | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/userapi/storage/postgres/stats_table.go b/userapi/storage/postgres/stats_table.go index ca31407e6..f71900015 100644 --- a/userapi/storage/postgres/stats_table.go +++ b/userapi/storage/postgres/stats_table.go @@ -49,6 +49,10 @@ const countUsersLastSeenAfterSQL = "" + " GROUP BY localpart" + " ) u" +// Note on the following countR30UsersSQL and countR30UsersV2SQL: The different checks are intentional. +// This is to ensure the values reported by Dendrite are the same as by Synapse. +// Queries are taken from: https://github.com/matrix-org/synapse/blob/9ce51a47f6e37abd0a1275281806399d874eb026/synapse/storage/databases/main/stats.py + /* R30Users counts the number of 30 day retained users, defined as: - Users who have created their accounts more than 30 days ago diff --git a/userapi/storage/sqlite3/stats_table.go b/userapi/storage/sqlite3/stats_table.go index 653fc1332..af4c7ff98 100644 --- a/userapi/storage/sqlite3/stats_table.go +++ b/userapi/storage/sqlite3/stats_table.go @@ -49,6 +49,10 @@ const countUsersLastSeenAfterSQL = "" + " GROUP BY localpart" + " ) u" +// Note on the following countR30UsersSQL and countR30UsersV2SQL: The different checks are intentional. +// This is to ensure the values reported by Dendrite are the same as by Synapse. +// Queries are taken from: https://github.com/matrix-org/synapse/blob/9ce51a47f6e37abd0a1275281806399d874eb026/synapse/storage/databases/main/stats.py + /* R30Users counts the number of 30 day retained users, defined as: - Users who have created their accounts more than 30 days ago @@ -82,6 +86,10 @@ SELECT platform, COUNT(*) FROM ( ) u GROUP BY PLATFORM ` +// Note on the following countR30UsersSQL and countR30UsersV2SQL: The different checks are intentional. +// This is to ensure the values reported are the same as Synapse reports. +// Queries are taken from: https://github.com/matrix-org/synapse/blob/9ce51a47f6e37abd0a1275281806399d874eb026/synapse/storage/databases/main/stats.py + /* R30UsersV2 counts the number of 30 day retained users, defined as users that: - Appear more than once in the past 60 days diff --git a/userapi/storage/tables/stats_table_test.go b/userapi/storage/tables/stats_table_test.go index 2b875835b..11521c8b0 100644 --- a/userapi/storage/tables/stats_table_test.go +++ b/userapi/storage/tables/stats_table_test.go @@ -35,7 +35,7 @@ func mustMakeDBs(t *testing.T, dbType test.DBType) ( connStr, close := test.PrepareDBConnectionString(t, dbType) db, err := sqlutil.Open(&config.DatabaseOptions{ ConnectionString: config.DataSource(connStr), - }) + }, nil) if err != nil { t.Fatalf("failed to open db: %s", err) } @@ -144,7 +144,7 @@ func Test_UserStatistics(t *testing.T) { } if wantType != gotDB.Engine { // can't use DeepEqual, as the Version might differ - t.Errorf("UserStatistics() gotDB = %+v, want SQLite", gotDB.Engine) + t.Errorf("UserStatistics() got DB engine = %+v, want %s", gotDB.Engine, wantType) } })