aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-09-27 12:18:36 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-29 10:47:17 +0200
commit8c9c79921538fef769367728199d54b2013b7f0f (patch)
tree78558259b462a19775e07cf6428977621f0081f8 /src
parent05f1f813fa5dad4e9794dcccb0ea24e75a215029 (diff)
downloadhaketilo-hydrilla-8c9c79921538fef769367728199d54b2013b7f0f.tar.gz
haketilo-hydrilla-8c9c79921538fef769367728199d54b2013b7f0f.zip
[proxy] move payload dependencies installation logic to ConcreteMappingVersion class
Diffstat (limited to 'src')
-rw-r--r--src/hydrilla/proxy/state.py4
-rw-r--r--src/hydrilla/proxy/state_impl/items.py38
-rw-r--r--src/hydrilla/proxy/state_impl/payloads.py37
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
@@ -311,6 +311,10 @@ class MappingVersionRef(Ref, item_infos.CorrespondsToMappingDCMixin):
...
@abstractmethod
+ def ensure_depended_items_installed(self) -> None:
+ ...
+
+ @abstractmethod
def update_mapping_status(
self,
enabled: EnabledStatus,
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]]: