diff options
Diffstat (limited to 'app/workers/users')
-rw-r--r-- | app/workers/users/deactivate_dormant_users_worker.rb | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/app/workers/users/deactivate_dormant_users_worker.rb b/app/workers/users/deactivate_dormant_users_worker.rb index d7ea20e4b62..b14b7e67450 100644 --- a/app/workers/users/deactivate_dormant_users_worker.rb +++ b/app/workers/users/deactivate_dormant_users_worker.rb @@ -10,43 +10,23 @@ module Users feature_category :utilization - NUMBER_OF_BATCHES = 50 - BATCH_SIZE = 200 - PAUSE_SECONDS = 0.25 - def perform return if Gitlab.com? return unless ::Gitlab::CurrentSettings.current_application_settings.deactivate_dormant_users - with_context(caller_id: self.class.name.to_s) do - NUMBER_OF_BATCHES.times do - result = User.connection.execute(update_query) - - break if result.cmd_tuples == 0 - - sleep(PAUSE_SECONDS) - end - end + deactivate_users(User.dormant) + deactivate_users(User.with_no_activity) end private - def update_query - <<~SQL - UPDATE "users" - SET "state" = 'deactivated' - WHERE "users"."id" IN ( - (#{users.dormant.to_sql}) - UNION - (#{users.with_no_activity.to_sql}) - LIMIT #{BATCH_SIZE} - ) - SQL - end - - def users - User.select(:id).limit(BATCH_SIZE) + def deactivate_users(scope) + with_context(caller_id: self.class.name.to_s) do + scope.each_batch do |batch| + batch.each(&:deactivate) + end + end end end end |