Assure changes to process ids are updated in the cache on a file save,
and remove old references that no longer exist. Still some work to do here.
This commit is contained in:
parent
1d1c7a2db4
commit
221dea4bac
|
@ -160,6 +160,8 @@ class SpecFileService(FileSystemService):
|
|||
(ref for ref in references if ref.is_primary and ref.is_executable), None
|
||||
)
|
||||
|
||||
SpecFileService.clear_caches_for_file(file_name, process_model_info)
|
||||
|
||||
for ref in references:
|
||||
# If no valid primary process is defined, default to the first process in the
|
||||
# updated file.
|
||||
|
@ -235,6 +237,14 @@ class SpecFileService(FileSystemService):
|
|||
SpecFileService.update_message_trigger_cache(ref)
|
||||
SpecFileService.update_correlation_cache(ref)
|
||||
|
||||
@staticmethod
|
||||
def clear_caches_for_file(file_name: str, process_model_info: ProcessModelInfo) -> None:
|
||||
"""Clear all caches related to a file"""
|
||||
db.session.query(SpecReferenceCache).\
|
||||
filter(SpecReferenceCache.file_name == file_name).\
|
||||
filter(SpecReferenceCache.process_model_id == process_model_info.id).delete()
|
||||
# fixme: likely the other caches should be cleared as well, but we don't have a clean way to do so yet.
|
||||
|
||||
@staticmethod
|
||||
def clear_caches() -> None:
|
||||
"""Clear_caches."""
|
||||
|
@ -254,6 +264,7 @@ class SpecFileService(FileSystemService):
|
|||
if process_id_lookup is None:
|
||||
process_id_lookup = SpecReferenceCache.from_spec_reference(ref)
|
||||
db.session.add(process_id_lookup)
|
||||
db.session.commit()
|
||||
else:
|
||||
if ref.relative_path != process_id_lookup.relative_path:
|
||||
full_bpmn_file_path = SpecFileService.full_path_from_relative_path(
|
||||
|
|
|
@ -119,6 +119,45 @@ class TestSpecFileService(BaseTest):
|
|||
== self.call_activity_nested_relative_file_path
|
||||
)
|
||||
|
||||
def test_change_the_identifier_cleans_up_cache (
|
||||
self,
|
||||
app: Flask,
|
||||
client: FlaskClient,
|
||||
with_db_and_bpmn_file_cleanup: None,
|
||||
with_super_admin_user: UserModel,
|
||||
) -> None:
|
||||
""" When a BPMN processes identifier is changed in a file, the old id
|
||||
is removed from the cache"""
|
||||
old_identifier = "ye_old_identifier"
|
||||
process_id_lookup = SpecReferenceCache(
|
||||
identifier=old_identifier,
|
||||
relative_path=self.call_activity_nested_relative_file_path,
|
||||
file_name=self.bpmn_file_name,
|
||||
process_model_id=f"{self.process_group_id}/{self.process_model_id}",
|
||||
type='process'
|
||||
)
|
||||
db.session.add(process_id_lookup)
|
||||
db.session.commit()
|
||||
|
||||
self.create_group_and_model_with_bpmn(
|
||||
client=client,
|
||||
user=with_super_admin_user,
|
||||
process_group_id=self.process_group_id,
|
||||
process_model_id=self.process_model_id,
|
||||
bpmn_file_name=self.bpmn_file_name,
|
||||
bpmn_file_location=self.process_model_id,
|
||||
)
|
||||
|
||||
bpmn_process_id_lookups = SpecReferenceCache.query.all()
|
||||
assert len(bpmn_process_id_lookups) == 1
|
||||
assert bpmn_process_id_lookups[0].identifier != old_identifier
|
||||
assert bpmn_process_id_lookups[0].identifier == "Level1"
|
||||
assert (
|
||||
bpmn_process_id_lookups[0].relative_path
|
||||
== self.call_activity_nested_relative_file_path
|
||||
)
|
||||
|
||||
|
||||
def test_load_reference_information(
|
||||
self,
|
||||
app: Flask,
|
||||
|
|
Loading…
Reference in New Issue