From d1495bb991322c0635a84ddac6466541f749c8ca Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 18 Aug 2023 10:25:54 +0530 Subject: [PATCH] perf: ignore log links and disable in background jobs Scheduled job type keeps getting updated for every scheduled job. This is not required at all and not triggered by user. This feature is for prioritizing user selected links, background jobs should be ignored. --- frappe/model/utils/link_count.py | 43 +++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) 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")