diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /app/workers/users | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
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 |