docbrown/app/workers/moderator/sink_articles_worker.rb
Andy Zhao acd3b92b32
Add sink user service and specs for mass vomits (#6006)
* Add sink user service and specs for mass vomits

* Use new score calculation

* Lower articles' scores instead and make async

* Add lower score functionality to controllers

* Remove unused variable

* Use correct var and add missing arg

* Remove unused status

* Add composite index for reactable_type and ID

* Use alias instead of additional boolean

* Use medium priority for sink worker

* Log to honeybadger and not logs

* Log the error and not a string
2020-02-17 10:29:50 -05:00

20 lines
624 B
Ruby

module Moderator
class SinkArticlesWorker
include Sidekiq::Worker
sidekiq_options queue: :medium_priority, retry: 10
def perform(user_id)
user = User.find_by(id: user_id)
return unless user
articles = Article.where(user: user)
reactions = Reaction.where(reactable: articles)
new_score = reactions.sum(:points) + Reaction.where(reactable: user).sum(:points)
articles.update_all(score: new_score)
rescue StandardError => e
DataDogStatsClient.count("moderators.sink", 1, tags: ["action:failed", "user_id:#{user.id}"])
Honeybadger.notify(e)
end
end
end