Class: CleanUpSpammyUsersJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- CleanUpSpammyUsersJob
- Defined in:
- /var/apps/qpixel/app/jobs/clean_up_spammy_users_job.rb
Instance Method Summary collapse
Methods inherited from ApplicationJob
Constructor Details
This class inherits a constructor from ApplicationJob
Instance Method Details
#perform(created_after: 1.month.ago) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File '/var/apps/qpixel/app/jobs/clean_up_spammy_users_job.rb', line 4 def perform(created_after: 1.month.ago) # Select potential spammers: users created within timeframe, who are not deleted, who have posted but all posts have # since been deleted (no live posts). possible_spammers = User.joins('inner join posts on users.id = posts.user_id') .where('users.created_at >= ?', created_after) .where(users: { deleted: false }).group('users.id').having('count(posts.id) > 0') .having('count(distinct if(posts.deleted = true, null, posts.id)) = 0') blocked = 0 possible_spammers.each do |spammer| all_posts_spam = spammer.posts.all? do |post| # A post is considered spam if there are any helpful spam flags on it. post.flags.any? do |flag| flag.post_flag_type.name == "it's spam" && flag.status == 'helpful' end end next unless all_posts_spam blocked += 1 spammer.block('automatic block from spam cleanup job', length: 2.years) spammer.soft_delete(User.system) end logger.info "Considered #{possible_spammers.size} potential spammers, blocked #{blocked}." end |