From 51a6b9dc5764b93b6849731bd0897797a148c91b Mon Sep 17 00:00:00 2001 From: NeatGuyCoding <15627489+NeatGuyCoding@users.noreply.github.com> Date: Tue, 29 Jul 2025 16:35:33 +0800 Subject: [PATCH] hotfix: clear_all_annotations should also execute delete_annotation_index_task just like delete_app_annotation (#23093) Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- api/services/annotation_service.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/services/annotation_service.py b/api/services/annotation_service.py index 3239af998e..80dd63bf89 100644 --- a/api/services/annotation_service.py +++ b/api/services/annotation_service.py @@ -452,6 +452,11 @@ class AppAnnotationService: if not app: raise NotFound("App not found") + # if annotation reply is enabled, delete annotation index + app_annotation_setting = ( + db.session.query(AppAnnotationSetting).where(AppAnnotationSetting.app_id == app_id).first() + ) + annotations_query = db.session.query(MessageAnnotation).filter(MessageAnnotation.app_id == app_id) for annotation in annotations_query.yield_per(100): annotation_hit_histories_query = db.session.query(AppAnnotationHitHistory).filter( @@ -460,6 +465,12 @@ class AppAnnotationService: for annotation_hit_history in annotation_hit_histories_query.yield_per(100): db.session.delete(annotation_hit_history) + # if annotation reply is enabled, delete annotation index + if app_annotation_setting: + delete_annotation_index_task.delay( + annotation.id, app_id, current_user.current_tenant_id, app_annotation_setting.collection_binding_id + ) + db.session.delete(annotation) db.session.commit()