Skip to content

Commit

Permalink
PERF: correct clean up inactive so it does not clog scheduler
Browse files Browse the repository at this point in the history
also add a hard limit of 1000 users per job run so we do not clog the
scheduler

destroyer.destroy has a transaction and this can have some serious complications
with the open record set find_each has going
  • Loading branch information
SamSaffron committed Apr 9, 2019
1 parent ad5edc8 commit ec1c355
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/jobs/scheduled/clean_up_inactive_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def execute(args)
"posts.user_id IS NULL AND users.last_seen_at < ?",
SiteSetting.clean_up_inactive_users_after_days.days.ago
)
.find_each do |user|

.limit(1000)
.pluck(:id).each do |id|
begin
user = User.find(id)
destroyer.destroy(user, context: I18n.t("user.destroy_reasons.inactive_user"))
rescue => e
Discourse.handle_job_exception(e,
Expand Down

0 comments on commit ec1c355

Please sign in to comment.