From c6bc17c052573d75c7cce3bb609f92fe961d7998 Mon Sep 17 00:00:00 2001 From: John Behm Date: Mon, 22 Jan 2024 18:06:14 +0100 Subject: [PATCH] update user notification query --- queries/player_count_notification_messages.sql | 6 ++++-- sqlc/player_count_notification_messages.sql.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/queries/player_count_notification_messages.sql b/queries/player_count_notification_messages.sql index 954452a..d259646 100644 --- a/queries/player_count_notification_messages.sql +++ b/queries/player_count_notification_messages.sql @@ -7,12 +7,13 @@ SELECT COALESCE(pcm.message_id, 0)::bigint AS prev_message_id, pcn.user_id, MAX(COALESCE(np.num_players, 0))::smallint AS num_players -FROM tracking t +FROM channels c +JOIN tracking t ON c.channel_id = t.channel_id LEFT JOIN ( SELECT ac.address, count(*) AS num_players FROM active_server_clients ac GROUP BY ac.address - ORDER BY ac.address + ORDER BY ac.address ) np ON np.address = t.address JOIN player_count_notifications pcn ON ( @@ -23,6 +24,7 @@ ON ( ) LEFT JOIN player_count_notification_messages pcm ON (t.channel_id = pcm.channel_id) +WHERE c.running = TRUE GROUP BY t.guild_id, t.channel_id, pcm.message_id, pcn.user_id, num_players ORDER BY t.guild_id, t.channel_id, pcm.message_id, num_players, pcn.user_id; diff --git a/sqlc/player_count_notification_messages.sql.go b/sqlc/player_count_notification_messages.sql.go index c022b1e..393163c 100644 --- a/sqlc/player_count_notification_messages.sql.go +++ b/sqlc/player_count_notification_messages.sql.go @@ -34,12 +34,13 @@ SELECT COALESCE(pcm.message_id, 0)::bigint AS prev_message_id, pcn.user_id, MAX(COALESCE(np.num_players, 0))::smallint AS num_players -FROM tracking t +FROM channels c +JOIN tracking t ON c.channel_id = t.channel_id LEFT JOIN ( SELECT ac.address, count(*) AS num_players FROM active_server_clients ac GROUP BY ac.address - ORDER BY ac.address + ORDER BY ac.address ) np ON np.address = t.address JOIN player_count_notifications pcn ON ( @@ -50,6 +51,7 @@ ON ( ) LEFT JOIN player_count_notification_messages pcm ON (t.channel_id = pcm.channel_id) +WHERE c.running = TRUE GROUP BY t.guild_id, t.channel_id, pcm.message_id, pcn.user_id, num_players ORDER BY t.guild_id, t.channel_id, pcm.message_id, num_players, pcn.user_id `