]> git.xonotic.org Git - xonotic/xonstatdb.git/blobdiff - scripts/refresh_active_maps_mv.sql
Add a script to refresh active maps.
[xonotic/xonstatdb.git] / scripts / refresh_active_maps_mv.sql
diff --git a/scripts/refresh_active_maps_mv.sql b/scripts/refresh_active_maps_mv.sql
new file mode 100644 (file)
index 0000000..c23ef50
--- /dev/null
@@ -0,0 +1,10 @@
+begin;
+    delete from active_maps_mv;
+
+    insert into active_maps_mv
+    select row_number() over(order by count(1) desc) sort_order, m.map_id, m.name, count(1) games
+    from maps m join games g on m.map_id = g.map_id
+    where g.create_dt >= now() at time zone 'UTC' - interval '1 week'
+    group by 2, 3
+    ;
+end;