From 670e5cdf6ac66576a5b45f24eab4dc017265e998 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sun, 25 Oct 2020 07:09:37 +0000 Subject: [PATCH] Better logging when optimizing DB --- src/storage.cr | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/storage.cr b/src/storage.cr index 05557ef..592da0e 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -281,11 +281,19 @@ class Storage # Delete dangling IDs db.exec "delete from ids where id in " \ "(#{trash_ids.map { |i| "'#{i}'" }.join ","})" + Logger.debug "#{trash_ids.size} dangling IDs deleted" \ + if trash_ids.size > 0 # Delete dangling thumbnails - db.exec "delete from thumbnails where id not in (select id from ids)" + trash_thumbnails_count = db.query_one "select count(*) from " \ + "thumbnails where id not in " \ + "(select id from ids)", as: Int32 + if trash_thumbnails_count > 0 + db.exec "delete from thumbnails where id not in (select id from ids)" + Logger.info "#{trash_thumbnails_count} dangling thumbnails deleted" + end end - Logger.info "DB optimization finished" + Logger.debug "DB optimization finished" end end