From: Ward Vandewege Date: Mon, 14 Mar 2022 18:25:08 +0000 (-0400) Subject: Make the sql statement that clears old container logs more efficient by X-Git-Tag: 2.4.0~51 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/dc2b31ec8275995bde3ea855e66bb0137d8a4b62 Make the sql statement that clears old container logs more efficient by using now() instead of clock_timestamp(). The former is calculated once per transaction. refs #18763 Arvados-DCO-1.1-Signed-off-by: Ward Vandewege --- diff --git a/services/api/lib/tasks/delete_old_container_logs.rake b/services/api/lib/tasks/delete_old_container_logs.rake index 2146d9bc37..7a0ab3826a 100644 --- a/services/api/lib/tasks/delete_old_container_logs.rake +++ b/services/api/lib/tasks/delete_old_container_logs.rake @@ -11,7 +11,7 @@ namespace :db do desc "Remove old container log entries from the logs table" task delete_old_container_logs: :environment do - 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 clock_timestamp() - containers.finished_at > interval '#{Rails.configuration.Containers.Logging.MaxAge.to_i} seconds')" + 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 now() - containers.finished_at > interval '#{Rails.configuration.Containers.Logging.MaxAge.to_i} seconds')" ActiveRecord::Base.connection.execute(delete_sql) end