docs/moderations_performance_optimizations.md
This document outlines the performance optimizations implemented for the /mod (moderations#index) route to improve page load times.
The original moderation page was experiencing slow load times due to:
Added strategic database indexes to improve query performance:
-- Composite index for the main moderation query pattern
CREATE INDEX CONCURRENTLY index_articles_on_published_score_published_at_for_moderation
ON articles (published, score, published_at);
-- Index for nth_published_by_author filtering
CREATE INDEX CONCURRENTLY index_articles_on_published_nth_published_by_author
ON articles (published, nth_published_by_author);
-- Composite index for subforem + published + score queries
CREATE INDEX CONCURRENTLY index_articles_on_subforem_published_score_published_at
ON articles (subforem_id, published, score, published_at);
-- Index for reactions queries used in moderation
CREATE INDEX CONCURRENTLY index_reactions_on_reactable_and_user_for_moderation
ON reactions (reactable_id, reactable_type, user_id);
Created Moderations::ArticleFetcherService to:
Settings::UserExperience.feed_lookback_days (default: 10 days)Since moderators are only concerned with recent posts that are still relevant for the community feed, we implemented feed lookback filtering:
Settings::UserExperience.feed_lookback_days setting as the main feedapp/services/moderations/article_fetcher_service.rb - Optimized article fetching servicedb/migrate/20250821230000_add_moderation_indexes_to_articles.rb - Database indexes migrationspec/services/moderations/article_fetcher_service_spec.rb - Comprehensive test suiteapp/controllers/moderations_controller.rb - Refactored to use the new serviceThe optimizations are automatically applied when accessing the /mod route. No changes to the frontend or user interface are required.
Monitor performance improvements through:
Run the test suite to verify optimizations:
bundle exec rspec spec/services/moderations/article_fetcher_service_spec.rb
Run the database migration to add indexes:
bundle exec rails db:migrate
Monitor performance metrics after deployment to verify improvements.