diff --git a/frappe/model/utils/link_count.py b/frappe/model/utils/link_count.py index 65b5092d46..532a7807bd 100644 --- a/frappe/model/utils/link_count.py +++ b/frappe/model/utils/link_count.py @@ -5,11 +5,37 @@ from collections import defaultdict import frappe -ignore_doctypes = ("DocType", "Print Format", "Role", "Module Def", "Communication", "ToDo") +ignore_doctypes = { + "DocType", + "Print Format", + "Role", + "Module Def", + "Communication", + "ToDo", + "Version", + "Error Log", + "Scheduled Job Log", + "Event Sync Log", + "Event Update Log", + "Access Log", + "View Log", + "Activity Log", + "Energy Point Log", + "Notification Log", + "Email Queue", + "DocShare", + "Document Follow", + "Console Log", + "User", +} def notify_link_count(doctype, name): """updates link count for given document""" + + if doctype in ignore_doctypes or not frappe.request: + return + if not hasattr(frappe.local, "_link_count"): frappe.local._link_count = defaultdict(int) frappe.db.after_commit.add(flush_local_link_count) @@ -41,13 +67,12 @@ def update_link_count(): if link_count: for (doctype, name), count in link_count.items(): - if doctype not in ignore_doctypes: - try: - table = frappe.qb.DocType(doctype) - frappe.qb.update(table).set(table.idx, table.idx + count).where(table.name == name).run() - frappe.db.commit() - except Exception as e: - if not frappe.db.is_table_missing(e): # table not found, single - raise e + try: + table = frappe.qb.DocType(doctype) + frappe.qb.update(table).set(table.idx, table.idx + count).where(table.name == name).run() + frappe.db.commit() + except Exception as e: + if not frappe.db.is_table_missing(e): # table not found, single + raise e # reset the count frappe.cache.delete_value("_link_count")