Skip to content

Commit

Permalink
Always get the revision_count
Browse files Browse the repository at this point in the history
We provide the revision_count via the MS API, so should always try to fetch it. Doing so is
already a dependency to autoflagging, so doing it earlier doesn't change if we autoflag.
Fetching it earlier saves us the work of processing the flagging conditions for the cases
where the number of revisions disqualifies the post.
  • Loading branch information
makyen committed Aug 16, 2020
1 parent 449e629 commit e6aaadb
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions app/models/concerns/post_concerns/autoflagging.rb
Expand Up @@ -9,14 +9,23 @@ module PostConcerns::Autoflagging

def autoflag
Rails.logger.warn "[autoflagging] #{id}: Post#autoflag begin"
return 'Duplicate post' unless Post.where(link: link).count == 1
return 'Flagging disabled' unless FlagSetting['flagging_enabled'] == '1'
Rails.logger.warn "[autoflagging] #{id}: not a dupe"

dry_run = FlagSetting['dry_run'] == '1'
post = self

begin
Rails.logger.warn "[autoflagging] #{id}: before revision count"
post.fetch_revision_count
unless post.revision_count == 1
Rails.logger.warn "[autoflagging] #{id}: vandalized"
post.send_not_autoflagged
return 'More than one revision'
end

return 'Duplicate post' unless Post.where(link: link).count == 1
return 'Flagging disabled' unless FlagSetting['flagging_enabled'] == '1'
Rails.logger.warn "[autoflagging] #{id}: not a dupe"

dry_run = FlagSetting['dry_run'] == '1'

conditions = post.site.flag_conditions.where(flags_enabled: true)
available_user_ids = {}
conditions.each do |condition|
Expand All @@ -34,14 +43,6 @@ def autoflag
return 'No users eligible to flag'
end

Rails.logger.warn "[autoflagging] #{id}: before revision count"
post.fetch_revision_count
unless post.revision_count == 1
Rails.logger.warn "[autoflagging] #{id}: vandalized"
post.send_not_autoflagged
return 'More than one revision'
end

Rails.logger.warn "[autoflagging] #{id}: lottery begin"

# Defined by the scaled_max_flags FlagSetting
Expand Down

0 comments on commit e6aaadb

Please sign in to comment.