diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-03 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-03 09:08:42 +0000 |
commit | f14507e586a7f75f0fb71a1d8468b7361be860d4 (patch) | |
tree | a8aa547b517a7ae5626c902bfb558c1fc5386c4e /app/workers | |
parent | f4d27d532e3abeecd1caffeb3a56e698ae982e5b (diff) | |
download | gitlab-ce-f14507e586a7f75f0fb71a1d8468b7361be860d4.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/prune_old_events_worker.rb | 16 | ||||
-rw-r--r-- | app/workers/prune_web_hook_logs_worker.rb | 17 |
2 files changed, 8 insertions, 25 deletions
diff --git a/app/workers/prune_old_events_worker.rb b/app/workers/prune_old_events_worker.rb index f421e8dbf59..1d915832833 100644 --- a/app/workers/prune_old_events_worker.rb +++ b/app/workers/prune_old_events_worker.rb @@ -6,18 +6,12 @@ class PruneOldEventsWorker feature_category_not_owned! - # rubocop: disable CodeReuse/ActiveRecord + DELETE_LIMIT = 10_000 + def perform # Contribution calendar shows maximum 12 months of events, we retain 3 years for data integrity. - # Double nested query is used because MySQL doesn't allow DELETE subqueries on the same table. - Event.unscoped.where( - '(id IN (SELECT id FROM (?) ids_to_remove))', - Event.unscoped.where( - 'created_at < ?', - (3.years + 1.day).ago) - .select(:id) - .limit(10_000)) - .delete_all + cutoff_date = (3.years + 1.day).ago + + Event.unscoped.created_before(cutoff_date).delete_with_limit(DELETE_LIMIT) end - # rubocop: enable CodeReuse/ActiveRecord end diff --git a/app/workers/prune_web_hook_logs_worker.rb b/app/workers/prune_web_hook_logs_worker.rb index 8e48b45fc34..69a1dd43e69 100644 --- a/app/workers/prune_web_hook_logs_worker.rb +++ b/app/workers/prune_web_hook_logs_worker.rb @@ -11,20 +11,9 @@ class PruneWebHookLogsWorker # The maximum number of rows to remove in a single job. DELETE_LIMIT = 50_000 - # rubocop: disable CodeReuse/ActiveRecord def perform - # MySQL doesn't allow "DELETE FROM ... WHERE id IN ( ... )" if the inner - # query refers to the same table. To work around this we wrap the IN body in - # another sub query. - WebHookLog - .where( - 'id IN (SELECT id FROM (?) ids_to_remove)', - WebHookLog - .select(:id) - .where('created_at < ?', 90.days.ago.beginning_of_day) - .limit(DELETE_LIMIT) - ) - .delete_all + cutoff_date = 90.days.ago.beginning_of_day + + WebHookLog.created_before(cutoff_date).delete_with_limit(DELETE_LIMIT) end - # rubocop: enable CodeReuse/ActiveRecord end |