aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/state_impl/concrete_state.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-09-27 13:42:55 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-29 10:47:17 +0200
commit00487547c4aff6bf0c94438768191960a3369365 (patch)
treeb8a27aa19258a27101bc5634e87fa1f9509457f2 /src/hydrilla/proxy/state_impl/concrete_state.py
parentfae35b53a4f63f60f0da96e75a0c2fc310217578 (diff)
downloadhaketilo-hydrilla-00487547c4aff6bf0c94438768191960a3369365.tar.gz
haketilo-hydrilla-00487547c4aff6bf0c94438768191960a3369365.zip
[proxy] facilitate manually pruning orphaned packages (including installed ones)
Diffstat (limited to 'src/hydrilla/proxy/state_impl/concrete_state.py')
-rw-r--r--src/hydrilla/proxy/state_impl/concrete_state.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/hydrilla/proxy/state_impl/concrete_state.py b/src/hydrilla/proxy/state_impl/concrete_state.py
index 04bb67f..d8706e8 100644
--- a/src/hydrilla/proxy/state_impl/concrete_state.py
+++ b/src/hydrilla/proxy/state_impl/concrete_state.py
@@ -146,7 +146,33 @@ class ConcreteHaketiloState(base.HaketiloStateWithFields):
self.rebuild_structures(rules=False)
- def prune_orphans(self) -> None:
+ def count_orphan_items(self) -> st.OrphanItemsStats:
+ with self.cursor() as cursor:
+ cursor.execute(
+ '''
+ SELECT
+ COALESCE(SUM(i.type = 'M'), 0),
+ COALESCE(SUM(i.type = 'R'), 0)
+ FROM
+ item_versions AS iv
+ JOIN items AS i USING (item_id)
+ JOIN orphan_iterations AS oi USING (repo_iteration_id)
+ WHERE
+ iv.active != 'R';
+ '''
+ )
+
+ (orphan_mappings, orphan_resources), = cursor.fetchall()
+
+ return st.OrphanItemsStats(orphan_mappings, orphan_resources)
+
+ def prune_orphan_items(self) -> None:
+ with self.cursor(transaction=True) as cursor:
+ _operations.prune_orphans(cursor, aggressive=True)
+
+ self.recompute_dependencies()
+
+ def soft_prune_orphan_items(self) -> None:
with self.cursor() as cursor:
assert self.connection.in_transaction