From ec6b1b6477cfc947061e717d80821db3118a1bde Mon Sep 17 00:00:00 2001 From: Zynh Ludwig Date: Thu, 21 Nov 2024 11:06:41 -0800 Subject: [PATCH] add cache cleaning queries --- queries/records/delete_expired_records.sql | 5 +++++ queries/records/get_expired_records.sql | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 queries/records/delete_expired_records.sql create mode 100644 queries/records/get_expired_records.sql diff --git a/queries/records/delete_expired_records.sql b/queries/records/delete_expired_records.sql new file mode 100644 index 0000000..0022bc2 --- /dev/null +++ b/queries/records/delete_expired_records.sql @@ -0,0 +1,5 @@ +DELETE FROM records +WHERE + downloads >= max_downloads + OR julianday('now') - julianday(uploaded) > 3 +RETURNING cache_name; diff --git a/queries/records/get_expired_records.sql b/queries/records/get_expired_records.sql new file mode 100644 index 0000000..ca719fb --- /dev/null +++ b/queries/records/get_expired_records.sql @@ -0,0 +1,7 @@ +SELECT + cache_name, + downloads, + max_downloads, + julianday('now') - julianday(uploaded) AS age +FROM records +WHERE downloads >= max_downloads OR age > 5;