reference-cache-integrity-fix-2 (#1645)

* delete from process caller table explicitly before removing from reference cache to hopefully avoid integrity errors

* check if reference cache id list has items to avoid unnecessary db calls

---------

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
Co-authored-by: Kevin Burnett <18027+burnettk@users.noreply.github.com>
This commit is contained in:
jasquat 2024-05-30 14:15:40 -04:00 committed by GitHub
parent be68db52ba
commit 2992798c5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View File

@ -20,13 +20,14 @@ class ProcessCallerService:
@staticmethod
def clear_cache_for_process_ids(reference_cache_ids: list[int]) -> None:
# query-invoked autoflush happens here
ProcessCallerRelationshipModel.query.filter(
or_(
ProcessCallerRelationshipModel.called_reference_cache_process_id.in_(reference_cache_ids),
ProcessCallerRelationshipModel.calling_reference_cache_process_id.in_(reference_cache_ids),
)
).delete()
if len(reference_cache_ids) > 0:
# query-invoked autoflush happens here
ProcessCallerRelationshipModel.query.filter(
or_(
ProcessCallerRelationshipModel.called_reference_cache_process_id.in_(reference_cache_ids),
ProcessCallerRelationshipModel.calling_reference_cache_process_id.in_(reference_cache_ids),
)
).delete()
@staticmethod
def add_caller(calling_process_identifier: str, called_process_identifiers: list[str]) -> None:

View File

@ -276,6 +276,10 @@ class SpecFileService(FileSystemService):
reference_cache_ids = []
for record in records:
reference_cache_ids.append(record.id)
ProcessCallerService.clear_cache_for_process_ids(reference_cache_ids)
for record in records:
db.session.delete(record)
@staticmethod