Skip to content

perf: cache hidden post set in Redis to prevent DB pool exhaustion - #370

Merged
kuny0707 merged 1 commit into
masterfrom
perf/hive-posts-status-indexes
Jun 11, 2026
Merged

perf: cache hidden post set in Redis to prevent DB pool exhaustion#370
kuny0707 merged 1 commit into
masterfrom
perf/hive-posts-status-indexes

Conversation

@ety001

@ety001 ety001 commented Apr 20, 2026

Copy link
Copy Markdown
Member

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.

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.
@kuny0707
kuny0707 merged commit e17b37c into master Jun 11, 2026
2 checks passed
@ety001
ety001 deleted the perf/hive-posts-status-indexes branch June 11, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants