From 9b8cc17cb1ccc96a3650143520e7b42a4c408aaf Mon Sep 17 00:00:00 2001 From: Alexey Murz Korepov Date: Tue, 12 May 2020 10:07:24 +0300 Subject: [PATCH] Added example: Show top 20 rooms by new events count in last --- SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md b/SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md index f12fe3f..6c589aa 100644 --- a/SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md +++ b/SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md @@ -64,6 +64,13 @@ device_lists_stream - 326903 user_directory_search - 316433 ``` +## Show top 20 rooms by new events count in last 1 day: +``` +SELECT e.room_id, r.name, COUNT(e.event_id) cnt FROM events e +LEFT JOIN room_stats_state r USING (room_id) +WHERE e.origin_server_ts >= DATE_PART('epoch', NOW() - INTERVAL '1 day') * 1000 GROUP BY e.room_id, r.name ORDER BY cnt DESC LIMIT 20; +``` + ## Show top 20 users on homeserver by sent events (messages) at last month: ``` SELECT user_id, SUM(total_events)