Skip to content

Commit 1172905

Browse files
committed
Replace TODO with rationale: full scan is optimal without reacted_at index
Benchmarked incremental approaches (CTE recent pairs: 13.7s, IN active users: 8.8s) against the current full scan (6.0s). All slower because no index on reacted_at, and adding one isn't worth the storage cost (indexes already 1.9GB > table 1.8GB).
1 parent e0b3ad0 commit 1172905

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/stats/user_meme_source.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55

66
async def calculate_user_meme_source_stats() -> None:
7-
# TODO: update only recently active users
7+
# Full scan (~6s). Incremental update needs an index on reacted_at
8+
# which isn't worth the storage cost (indexes already 1.9GB > table 1.8GB).
89
insert_query = """
910
INSERT INTO user_meme_source_stats (
1011
user_id,
@@ -22,7 +23,7 @@ async def calculate_user_meme_source_stats() -> None:
2223
FROM user_meme_reaction R
2324
INNER JOIN meme M
2425
ON M.id = R.meme_id
25-
WHERE reaction_id IS NOT NULL -- only reacted
26+
WHERE reaction_id IS NOT NULL
2627
GROUP BY 1,2
2728
ON CONFLICT (user_id, meme_source_id) DO
2829
UPDATE SET

0 commit comments

Comments
 (0)