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.
This commit is contained in:
Ankush Menat 2023-08-18 10:25:54 +05:30
parent 06ba61ff97
commit d1495bb991

View file

@ -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")