Skip to content

Commit

Permalink
Merge branch 'master' into issue_2201_editing_locked_db
Browse files Browse the repository at this point in the history
# Conflicts:
#	spinedb_api/db_mapping_remove_mixin.py
  • Loading branch information
Henrik Koski committed Aug 18, 2023
2 parents f8babde + bd337e8 commit 189eac0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions spinedb_api/db_mapping_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,9 @@ def _reset_mapping(self):
self.connection.execute(table.delete())
self.connection.execute("INSERT INTO alternative VALUES (1, 'Base', 'Base alternative', null)")

def make_cache(self, tablenames, include_descendants=False, include_ancestors=False, force_tablenames=None):
def make_cache(
self, tablenames, include_descendants=False, include_ancestors=False, force_tablenames=None, keep_existing=False
):
if include_descendants:
tablenames |= {
descendant for tablename in tablenames for descendant in self.descendant_tablenames.get(tablename, ())
Expand All @@ -2031,7 +2033,7 @@ def make_cache(self, tablenames, include_descendants=False, include_ancestors=Fa
if force_tablenames:
tablenames |= force_tablenames
for tablename in tablenames & self.cache_sqs.keys():
self._do_advance_cache_query(tablename)
self._do_advance_cache_query(tablename, keep_existing)
return self.cache

def _advance_cache_query(self, tablename, callback=None):
Expand All @@ -2043,10 +2045,10 @@ def _advance_cache_query(self, tablename, callback=None):
callback()
return advanced

def _do_advance_cache_query(self, tablename):
def _do_advance_cache_query(self, tablename, keep_existing=False):
table_cache = self.cache.table_cache(tablename)
for x in self.query(getattr(self, self.cache_sqs[tablename])).yield_per(1000).enable_eagerloads(False):
table_cache.add_item(x._asdict())
table_cache.add_item(x._asdict(), keep_existing)

def _items_with_type_id(self, tablename, *items):
type_id = {
Expand Down
1 change: 1 addition & 0 deletions spinedb_api/db_mapping_remove_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def cascading_ids(self, cache=None, **kwargs):
force_tablenames={"entity_metadata", "parameter_value_metadata"}
if any(x in kwargs for x in ("entity_metadata", "parameter_value_metadata", "metadata"))
else None,
keep_existing=True,
)
except DBAPIError as e:
raise SpineDBAPIError(f"Fail to get cascading ids: {e.orig.args}")
Expand Down

0 comments on commit 189eac0

Please sign in to comment.