perf: ensure hive_posts_status indexes exist (migration v28)#369
Closed
perf: ensure hive_posts_status indexes exist (migration v28)#369
Conversation
The hide_pids_by_ids function was querying hive_posts_status on every API request with 'WHERE list_type=1 AND post_id IN :ids'. Even though the table is small (13K rows, 832KB) and has proper indexes, under burst traffic this flooded the DB connection pool (size=30), causing cascading timeouts up to 427 seconds. Confirmed via production RDS debug API (2026-04-20): - hive_posts_status: 13,764 rows, indexes exist and healthy - DB version: 27 (all migrations applied) - Scalyr showed 0.0% idle during peak, 56 queries >100s (pool queuing) Fix: Cache the full hidden post ID set in Redis (60s TTL) and filter in Python. This turns every hide_pids_by_ids call into a Redis lookup + Python set intersection, eliminating the DB query entirely.
f2d1ccf to
17ac698
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scalyr analysis (2026-04-20 06:09 CST) showed hive_posts_status queries taking up to 427s (7 minutes), causing:
Root cause: Indexes from migration v20 may not exist in production. v20 used non-CONCURRENTLY DDL which can fail under load.
Migration v28 ensures these indexes exist using CONCURRENTLY IF NOT EXISTS: