Make the sql statement that clears old container logs more efficient by
authorWard Vandewege <ward@curii.com>
Mon, 14 Mar 2022 18:25:08 +0000 (14:25 -0400)
committerWard Vandewege <ward@curii.com>
Mon, 14 Mar 2022 18:25:08 +0000 (14:25 -0400)
using now() instead of clock_timestamp(). The former is calculated once
per transaction.

refs #18763

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

services/api/lib/tasks/delete_old_container_logs.rake

index 2146d9bc379409fbe2bffaac73dd273c29fb93e3..7a0ab3826ab1c08beee1361ff81b654b4ccff86d 100644 (file)
@@ -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