From: radhika Date: Sat, 24 Sep 2016 23:31:09 +0000 (-0400) Subject: 9514: Use sql to issue delete sql without getting ids in batch. X-Git-Tag: 1.1.0~704^2~1 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/f40544f6523bf2d54b288a64af7cab7469741512 9514: Use sql to issue delete sql without getting ids in batch. --- diff --git a/services/api/lib/tasks/delete_old_container_logs.rake b/services/api/lib/tasks/delete_old_container_logs.rake index 8c32331dde..3421fb8b96 100644 --- a/services/api/lib/tasks/delete_old_container_logs.rake +++ b/services/api/lib/tasks/delete_old_container_logs.rake @@ -5,13 +5,10 @@ namespace :db do desc "Remove old container log entries from the logs table" + task delete_old_container_logs: :environment do - Log.select("logs.id"). - joins("JOIN containers ON object_uuid = containers.uuid"). - where("event_type in ('stdout', 'stderr', 'arv-mount', 'crunch-run', 'crunchstat') AND containers.log IS NOT NULL AND containers.finished_at < :age", - age: Rails.configuration.clean_container_log_rows_after.ago). - find_in_batches do |old_log_ids| - Log.where(id: old_log_ids.map(&:id)).delete_all - end + delete_sql = "DELETE FROM logs WHERE id in (SELECT logs.id FROM logs JOIN containers ON logs.object_uuid = containers.uuid WHERE event_type IN ('stdout', 'stderr', 'arv-mount', 'crunch-run', 'crunchstat') AND containers.log IS NOT NULL AND containers.finished_at < '#{Rails.configuration.clean_container_log_rows_after.ago}')" + + ActiveRecord::Base.connection.execute(delete_sql) end end