Clear caches when deleting a file (#826)

This commit is contained in:
jbirddog 2023-12-21 14:12:48 -05:00 committed by GitHub
parent 88030781d6
commit 2f83a68787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -16,6 +16,7 @@ from werkzeug.datastructures import FileStorage
from spiffworkflow_backend.exceptions.api_error import ApiError from spiffworkflow_backend.exceptions.api_error import ApiError
from spiffworkflow_backend.interfaces import IdToProcessGroupMapping from spiffworkflow_backend.interfaces import IdToProcessGroupMapping
from spiffworkflow_backend.models.db import db
from spiffworkflow_backend.models.file import FileType from spiffworkflow_backend.models.file import FileType
from spiffworkflow_backend.models.process_group import ProcessGroup from spiffworkflow_backend.models.process_group import ProcessGroup
from spiffworkflow_backend.models.process_instance_report import ProcessInstanceReportModel from spiffworkflow_backend.models.process_instance_report import ProcessInstanceReportModel
@ -258,6 +259,7 @@ def process_model_file_delete(modified_process_model_identifier: str, file_name:
try: try:
SpecFileService.delete_file(process_model, file_name) SpecFileService.delete_file(process_model, file_name)
db.session.commit()
except FileNotFoundError as exception: except FileNotFoundError as exception:
raise ( raise (
ApiError( ApiError(

View File

@ -228,13 +228,9 @@ class SpecFileService(FileSystemService):
full_file_path = SpecFileService.full_file_path(process_model, file_name) full_file_path = SpecFileService.full_file_path(process_model, file_name)
return FileSystemService._timestamp(full_file_path) return FileSystemService._timestamp(full_file_path)
@staticmethod @classmethod
def delete_file(process_model: ProcessModelInfo, file_name: str) -> None: def delete_file(cls, process_model: ProcessModelInfo, file_name: str) -> None:
# Fixme: Remember to remove the lookup files when the process_model file is removed. cls.clear_caches_for_file(file_name, process_model)
# lookup_files = session.query(LookupFileModel).filter_by(file_model_id=file_id).all()
# for lf in lookup_files:
# session.query(LookupDataModel).filter_by(lookup_file_model_id=lf.id).delete()
# session.query(LookupFileModel).filter_by(id=lf.id).delete()
full_file_path = SpecFileService.full_file_path(process_model, file_name) full_file_path = SpecFileService.full_file_path(process_model, file_name)
os.remove(full_file_path) os.remove(full_file_path)