Skip to content

Commit

Permalink
Fix item removal ovewriting updates in database cache (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen authored Aug 17, 2023
2 parents f50f7ba + 071da6a commit bd337e8
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 @@ -83,6 +83,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,
)
ids = {}
self._merge(ids, self._object_class_cascading_ids(kwargs.get("object_class", set()), cache))
Expand Down

0 comments on commit bd337e8

Please sign in to comment.