Skip to content

Commit 8c64cd8

Browse files
committed
feat: optimize warp stats to query and update in bulk
- Removed duplicate code - Simplified warp stat structs to reuse a single struct as they all work the same - Now queries all warp stats with the counts in a single query instead of querying all stats and then each users count individually - Now updates all stats in batchs of 1000 instead of 1 at a time
1 parent 12496bd commit 8c64cd8

29 files changed

Lines changed: 434 additions & 399 deletions

File tree

sql/warps_stats/collab/get_all.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH warp_counts AS (
2+
SELECT uid, COUNT(*) AS warp_count
3+
FROM warps_collab
4+
GROUP BY uid
5+
)
6+
SELECT
7+
stats.uid,
8+
stats.luck_4,
9+
stats.luck_5,
10+
COALESCE(wc.warp_count, 0) AS warp_count
11+
FROM warps_stats_collab stats
12+
LEFT JOIN warp_counts wc ON stats.uid = wc.uid
13+
WHERE wc.warp_count >= 100;

sql/warps_stats/collab_lc/get_all.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH warp_counts AS (
2+
SELECT uid, COUNT(*) AS warp_count
3+
FROM warps_collab_lc
4+
GROUP BY uid
5+
)
6+
SELECT
7+
stats.uid,
8+
stats.luck_4,
9+
stats.luck_5,
10+
COALESCE(wc.warp_count, 0) AS warp_count
11+
FROM warps_stats_collab_lc stats
12+
LEFT JOIN warp_counts wc ON stats.uid = wc.uid
13+
WHERE wc.warp_count >= 100;

sql/warps_stats/lc/get_all.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH warp_counts AS (
2+
SELECT uid, COUNT(*) AS warp_count
3+
FROM warps_lc
4+
GROUP BY uid
5+
)
6+
SELECT
7+
stats.uid,
8+
stats.luck_4,
9+
stats.luck_5,
10+
COALESCE(wc.warp_count, 0) AS warp_count
11+
FROM warps_stats_lc stats
12+
LEFT JOIN warp_counts wc ON stats.uid = wc.uid
13+
WHERE wc.warp_count >= 100;

sql/warps_stats/special/get_all.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH warp_counts AS (
2+
SELECT uid, COUNT(*) AS warp_count
3+
FROM warps_special
4+
GROUP BY uid
5+
)
6+
SELECT
7+
stats.uid,
8+
stats.luck_4,
9+
stats.luck_5,
10+
COALESCE(wc.warp_count, 0) AS warp_count
11+
FROM warps_stats_special stats
12+
LEFT JOIN warp_counts wc ON stats.uid = wc.uid
13+
WHERE wc.warp_count >= 100;

sql/warps_stats/standard/get_all.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH warp_counts AS (
2+
SELECT uid, COUNT(*) AS warp_count
3+
FROM warps_standard
4+
GROUP BY uid
5+
)
6+
SELECT
7+
stats.uid,
8+
stats.luck_4,
9+
stats.luck_5,
10+
COALESCE(wc.warp_count, 0) AS warp_count
11+
FROM warps_stats_standard stats
12+
LEFT JOIN warp_counts wc ON stats.uid = wc.uid
13+
WHERE wc.warp_count >= 100;

0 commit comments

Comments
 (0)