From 0322c1a36ea9ca92c217d9cdec52a0ee5d687f72 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 28 Mar 2024 13:28:59 +0530 Subject: [PATCH] fix: use sql to clear comments (cherry picked from commit 1f46c1530e68263ca2b5f9f86f59bb06063cd05e) --- .../transaction_deletion_record.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py index db5024bbc199..c32df4ec9d03 100644 --- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py +++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py @@ -388,17 +388,11 @@ def delete_communications(self, doctype, reference_doc_names): frappe.delete_doc("Communication", batch, ignore_permissions=True) def delete_comments(self, doctype, reference_doc_names): - comments = frappe.get_all( - "Comment", - filters={"reference_doctype": doctype, "reference_name": ["in", reference_doc_names]}, - ) - comment_names = [c.name for c in comments] - - if not comment_names: - return - - for batch in create_batch(comment_names, self.batch_size): - frappe.delete_doc("Comment", batch, ignore_permissions=True) + if reference_doc_names: + comment = qb.DocType("Comment") + qb.from_(comment).delete().where( + (comment.reference_doctype == doctype) & (comment.reference_name.isin(reference_doc_names)) + ).run() def unlink_attachments(self, doctype, reference_doc_names): files = frappe.get_all(