Skip to content

perf: optimize slow queries for trending/feed/community APIs#368

Open
ety001 wants to merge 1 commit intomasterfrom
fix/slow-query-optimization-2026-04-05
Open

perf: optimize slow queries for trending/feed/community APIs#368
ety001 wants to merge 1 commit intomasterfrom
fix/slow-query-optimization-2026-04-05

Conversation

@ety001
Copy link
Copy Markdown
Member

@ety001 ety001 commented Apr 4, 2026

Based on beta-hivemind-slow-query-analysis.md report:

Database Indexes (v26 -> v27):

  • Add hive_posts_cache_temp_ix6b: depth+sc_trend index for trending queries
  • Add hive_posts_cache_temp_ix30b: community+depth+sc_trend index for community queries
  • Add idx_feed_cache_account_created_desc: optimize feed/blog ORDER BY
  • Add idx_reblogs_post_account: optimize NOT EXISTS subquery

Query Optimization:

  • Replace 'author NOT IN (subquery)' with NOT EXISTS in:
    • pids_by_community()
    • pids_by_category()
  • NOT EXISTS performs better than NOT IN with PostgreSQL

Expected improvement:

  • Trending queries: 281ms -> ~20ms (14x faster)
  • Feed queries: 30ms -> ~5ms (6x faster)
  • Community queries: 23ms -> ~3ms (7x faster)
  • Total CPU: ~13.6% -> ~2%

Based on beta-hivemind-slow-query-analysis.md report:

Database Indexes (v26 -> v27):
- Add hive_posts_cache_temp_ix6b: depth+sc_trend index for trending queries
- Add hive_posts_cache_temp_ix30b: community+depth+sc_trend index for community queries
- Add idx_feed_cache_account_created_desc: optimize feed/blog ORDER BY
- Add idx_reblogs_post_account: optimize NOT EXISTS subquery

Query Optimization:
- Replace 'author NOT IN (subquery)' with NOT EXISTS in:
  - pids_by_community()
  - pids_by_category()
- NOT EXISTS performs better than NOT IN with PostgreSQL

Expected improvement:
- Trending queries: 281ms -> ~20ms (14x faster)
- Feed queries: 30ms -> ~5ms (6x faster)
- Community queries: 23ms -> ~3ms (7x faster)
- Total CPU: ~13.6% -> ~2%
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.

1 participant