aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/state_impl/_operations/prune_orphans.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-09-08 17:59:40 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-28 14:03:18 +0200
commit45e5cf8dc3ca936e2db8e7e45689d0a3331aad43 (patch)
tree83f0b13f0fbb6d29862ac91ac0597e1c5c64719e /src/hydrilla/proxy/state_impl/_operations/prune_orphans.py
parent04853ff19450c5925a7c9bacc11abe90e75f8510 (diff)
downloadhaketilo-hydrilla-45e5cf8dc3ca936e2db8e7e45689d0a3331aad43.tar.gz
haketilo-hydrilla-45e5cf8dc3ca936e2db8e7e45689d0a3331aad43.zip
[proxy] make package auto-installation work
Diffstat (limited to 'src/hydrilla/proxy/state_impl/_operations/prune_orphans.py')
-rw-r--r--src/hydrilla/proxy/state_impl/_operations/prune_orphans.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/hydrilla/proxy/state_impl/_operations/prune_orphans.py b/src/hydrilla/proxy/state_impl/_operations/prune_orphans.py
index f4ebd52..5a3f4f0 100644
--- a/src/hydrilla/proxy/state_impl/_operations/prune_orphans.py
+++ b/src/hydrilla/proxy/state_impl/_operations/prune_orphans.py
@@ -102,6 +102,30 @@ WHERE
file_id IN removed_files;
'''
+_forget_files_data_sql = '''
+WITH forgotten_files AS (
+ SELECT
+ f.file_id
+ FROM
+ files AS f
+ JOIN file_uses AS fu
+ USING (file_id)
+ LEFT JOIN item_versions AS iv
+ ON (fu.item_version_id = iv.item_version_id AND
+ iv.installed = 'I')
+ GROUP BY
+ f.file_id
+ HAVING
+ COUNT(iv.item_version_id) = 0
+)
+UPDATE
+ files
+SET
+ data = NULL
+WHERE
+ file_id IN forgotten_files;
+'''
+
_remove_repo_iterations_sql = '''
WITH removed_iterations AS (
SELECT
@@ -141,5 +165,6 @@ def prune_orphans(cursor: sqlite3.Cursor) -> None:
cursor.execute(sql)
cursor.execute(_remove_items_sql)
cursor.execute(_remove_files_sql)
+ cursor.execute(_forget_files_data_sql)
cursor.execute(_remove_repo_iterations_sql)
cursor.execute(_remove_repos_sql)