From 8c9c79921538fef769367728199d54b2013b7f0f Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 27 Sep 2022 12:18:36 +0200 Subject: [proxy] move payload dependencies installation logic to ConcreteMappingVersion class --- src/hydrilla/proxy/state.py | 4 ++++ src/hydrilla/proxy/state_impl/items.py | 38 +++++++++++++++++++++++++++++++ src/hydrilla/proxy/state_impl/payloads.py | 37 ++++-------------------------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/hydrilla/proxy/state.py b/src/hydrilla/proxy/state.py index a94cd75..7613d54 100644 --- a/src/hydrilla/proxy/state.py +++ b/src/hydrilla/proxy/state.py @@ -310,6 +310,10 @@ class MappingVersionRef(Ref, item_infos.CorrespondsToMappingDCMixin): def uninstall(self) -> t.Optional['MappingVersionRef']: ... + @abstractmethod + def ensure_depended_items_installed(self) -> None: + ... + @abstractmethod def update_mapping_status( self, diff --git a/src/hydrilla/proxy/state_impl/items.py b/src/hydrilla/proxy/state_impl/items.py index 08c3114..02508f8 100644 --- a/src/hydrilla/proxy/state_impl/items.py +++ b/src/hydrilla/proxy/state_impl/items.py @@ -413,6 +413,44 @@ class ConcreteMappingVersionRef(st.MappingVersionRef): def uninstall(self) -> t.Optional['ConcreteMappingVersionRef']: return _uninstall_version(self) + def ensure_depended_items_installed(self) -> None: + with self.state.cursor(transaction=True) as cursor: + cursor.execute( + ''' + UPDATE + item_versions + SET + installed = 'I' + WHERE + item_version_id = ?; + ''', + (self.id,) + ) + + cursor.execute( + ''' + WITH depended_resource_ids AS ( + SELECT + rdd.resource_item_id + FROM + payloads AS p + JOIN resolved_depended_resources AS rdd + USING (payload_id) + WHERE + p.mapping_item_id = ? + ) + UPDATE + item_versions + SET + installed = 'I' + WHERE + item_version_id IN depended_resource_ids; + ''', + (self.id,) + ) + + self.state.pull_missing_files() + @contextmanager def _mapping_ref(self) -> t.Iterator[ConcreteMappingRef]: with self.state.cursor(transaction=True) as cursor: diff --git a/src/hydrilla/proxy/state_impl/payloads.py b/src/hydrilla/proxy/state_impl/payloads.py index ffd0ab3..74b8121 100644 --- a/src/hydrilla/proxy/state_impl/payloads.py +++ b/src/hydrilla/proxy/state_impl/payloads.py @@ -174,41 +174,12 @@ class ConcretePayloadRef(st.PayloadRef): (mapping_version_id,), = rows - cursor.execute( - ''' - UPDATE - item_versions - SET - installed = 'I' - WHERE - item_version_id = ?; - ''', - (mapping_version_id,) - ) - - cursor.execute( - ''' - WITH depended_resource_ids AS ( - SELECT - rdd.resource_item_id - FROM - payloads AS p - JOIN resolved_depended_resources AS rdd - USING (payload_id) - WHERE - payload_id = ? - ) - UPDATE - item_versions - SET - installed = 'I' - WHERE - item_version_id IN depended_resource_ids; - ''', - (self.id,) + mapping_version_ref = items.ConcreteMappingVersionRef( + id = str(mapping_version_id), + state = self.state ) - self.state.pull_missing_files() + mapping_version_ref.ensure_depended_items_installed() def get_script_paths(self) \ -> t.Iterable[t.Sequence[str]]: -- cgit v1.2.3