From d68b1031163c6ad88cf78d304f5c2ca914c53884 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 15 Nov 2022 16:04:05 -0500 Subject: [PATCH 1/2] 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. --- .../services/spec_file_service.py | 11 ++++++ .../unit/test_spec_file_service.py | 39 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py index 4f160b12..59241de7 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/spec_file_service.py @@ -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( diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_spec_file_service.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_spec_file_service.py index d9a7adcb..b5e5aa3c 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_spec_file_service.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_spec_file_service.py @@ -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, From 0887c11245764b84158b8699a5256770a7dfc687 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 15 Nov 2022 16:19:52 -0500 Subject: [PATCH 2/2] need to filter on process here, or a DMN with the same name will obscure the BPMN. --- .../services/process_instance_processor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py index 10913a2e..440b8b55 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py @@ -703,6 +703,8 @@ class ProcessInstanceProcessor: spec_reference = SpecReferenceCache.query.filter_by( identifier=bpmn_process_identifier + ).filter_by( + type='process' ).first() bpmn_file_full_path = None if spec_reference is None: @@ -1019,7 +1021,7 @@ class ProcessInstanceProcessor: spiff_logger = logging.getLogger("spiff") for handler in spiff_logger.handlers: if hasattr(handler, "bulk_insert_logs"): - handler.bulk_insert_logs() # type: ignore + handler.bulk_insert_logs() # type: ignoreidentifier db.session.commit() except WorkflowTaskExecException as we: