modqueue: fix performance regression from including appeals.

* Add index on posts.is_deleted. The modqueue was slow because we the
 appeal condition wasn't constrained to deleted posts, so it degraded to
 a full table scan.

* Avoid extra queries for calculating the page count and disapproval counts.
This commit is contained in:
evazion
2020-08-16 14:27:34 -05:00
parent 16cfdb8321
commit f337902c57
4 changed files with 19 additions and 5 deletions

View File

@@ -63,7 +63,7 @@ class Post < ApplicationRecord
scope :flagged, -> { where(is_flagged: true) }
scope :banned, -> { where(is_banned: true) }
scope :active, -> { where(is_pending: false, is_deleted: false, is_flagged: false).where.not(id: PostAppeal.pending) }
scope :appealed, -> { where(id: PostAppeal.pending.select(:post_id)) }
scope :appealed, -> { deleted.where(id: PostAppeal.pending.select(:post_id)) }
scope :in_modqueue, -> { pending.or(flagged).or(appealed) }
scope :expired, -> { pending.where("posts.created_at < ?", Danbooru.config.moderation_period.ago) }