perf: index tags for a document and dont track changes

This commit is contained in:
Ankush Menat 2025-02-04 12:02:23 +05:30
parent dd77f2c693
commit 7c67ca43ef
3 changed files with 27 additions and 6 deletions

View file

@ -46,7 +46,7 @@
}
],
"links": [],
"modified": "2024-03-23 16:03:39.781828",
"modified": "2025-02-04 12:02:03.779623",
"modified_by": "Administrator",
"module": "Desk",
"name": "Tag Link",
@ -79,6 +79,5 @@
"read_only": 1,
"sort_field": "creation",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
"states": []
}

View file

@ -1,7 +1,7 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# License: MIT. See LICENSE
# import frappe
import frappe
from frappe.model.document import Document
@ -18,6 +18,23 @@ class TagLink(Document):
document_type: DF.Link | None
tag: DF.Link | None
title: DF.Data | None
# end: auto-generated types
pass
def clear_cache(self):
super().clear_cache()
if has_tags(self.document_type):
frappe.client_cache.delete_value(f"doctype_has_tags::{self.document_type}")
def on_doctype_update():
frappe.db.add_index("Tag Link", ["document_type", "document_name"])
def has_tags(doctype: str):
"""Short circuit checks for tags by first checking if users even uses tags"""
def check_db():
return frappe.db.exists("Tag Link", {"document_type": doctype})
return frappe.client_cache.get_value(f"doctype_has_tags::{doctype}", generator=check_db)

View file

@ -385,6 +385,11 @@ def get_view_logs(doc: "Document") -> list[dict]:
def get_tags(doctype: str, name: str) -> str:
from frappe.desk.doctype.tag_link.tag_link import has_tags
if not has_tags(doctype):
return
tags = frappe.get_all(
"Tag Link",
filters={"document_type": doctype, "document_name": name},