diff options
Diffstat (limited to 'src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py')
-rw-r--r-- | src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py index 494d130..4b48ce8 100644 --- a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py +++ b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py @@ -51,12 +51,13 @@ def _get_infos_of_type(cursor: sqlite3.Cursor, info_type: t.Type[AnyInfoVar],) \ cursor.execute( ''' SELECT - i.item_id, iv.definition, r.name, ri.iteration + ive.item_version_id, + ive.definition, + ive.repo, + ive.repo_iteration FROM - item_versions AS iv - JOIN items AS i USING (item_id) - JOIN repo_iterations AS ri USING (repo_iteration_id) - JOIN repos AS r USING (repo_id) + item_versions_extra AS ive + JOIN items AS i USING (item_id) WHERE i.type = ?; ''', @@ -65,9 +66,10 @@ def _get_infos_of_type(cursor: sqlite3.Cursor, info_type: t.Type[AnyInfoVar],) \ result: dict[int, AnyInfoVar] = {} - for item_id, definition, repo_name, repo_iteration in cursor.fetchall(): + for item_version_id, definition, repo_name, repo_iteration \ + in cursor.fetchall(): info = info_type.load(definition, repo_name, repo_iteration) - result[item_id] = info + result[item_version_id] = info return result @@ -93,11 +95,8 @@ def _recompute_dependencies_no_state_update_no_pull_files( ids_to_resources = _get_infos_of_type(cursor, item_infos.ResourceInfo) ids_to_mappings = _get_infos_of_type(cursor, item_infos.MappingInfo) - resources = ids_to_resources.items() - resources_to_ids = dict((info.identifier, id) for id, info in resources) - - mappings = ids_to_mappings.items() - mappings_to_ids = dict((info.identifier, id) for id, info in mappings) + resources_to_ids = dict((info, id) for id, info in ids_to_resources.items()) + mappings_to_ids = dict((info, id) for id, info in ids_to_mappings.items()) requirements = [*extra_requirements] @@ -150,17 +149,18 @@ def _recompute_dependencies_no_state_update_no_pull_files( UPDATE mapping_statuses SET - required = FALSE, active_version_id = NULL WHERE enabled != 'E'; ''' ) + cursor.execute("UPDATE item_versions SET active = 'N';") + cursor.execute('DELETE FROM payloads;') for choice in mapping_choices.values(): - mapping_ver_id = mappings_to_ids[choice.info.identifier] + mapping_ver_id = mappings_to_ids[choice.info] if choice.required: _mark_version_installed(cursor, mapping_ver_id) @@ -184,12 +184,23 @@ def _recompute_dependencies_no_state_update_no_pull_files( UPDATE mapping_statuses SET - required = ?, active_version_id = ? WHERE item_id = ?; ''', - (choice.required, mapping_ver_id, mapping_item_id) + (mapping_ver_id, mapping_item_id) + ) + + cursor.execute( + ''' + UPDATE + item_versions + SET + active = ? + WHERE + item_version_id = ?; + ''', + (mapping_ver_id, 'R' if choice.required else 'A') ) for num, (pattern, payload) in enumerate(choice.payloads.items()): @@ -226,7 +237,7 @@ def _recompute_dependencies_no_state_update_no_pull_files( (payload_id,), = cursor.fetchall() for res_num, resource_info in enumerate(payload.resources): - resource_ver_id = resources_to_ids[resource_info.identifier] + resource_ver_id = resources_to_ids[resource_info] if choice.required: _mark_version_installed(cursor, resource_ver_id) @@ -243,6 +254,27 @@ def _recompute_dependencies_no_state_update_no_pull_files( (payload_id, resource_ver_id, res_num) ) + new_status = 'R' if choice.required else 'A' + + cursor.execute( + ''' + UPDATE + item_versions + SET + active = ( + CASE + WHEN active = 'R' OR ? = 'R' THEN 'R' + WHEN active = 'A' OR ? = 'A' THEN 'A' + ELSE 'N' + END + ) + WHERE + item_version_id = ?; + ''', + (new_status, new_status, resource_ver_id) + ) + + def _recompute_dependencies_no_state_update( cursor: sqlite3.Cursor, extra_requirements: t.Iterable[sds.MappingRequirement] = (), |