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:
@@ -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) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user