Skip to content

Commit

Permalink
perf(dx): let developers know that they need to enable index on links (
Browse files Browse the repository at this point in the history
…frappe#21745)

* perf: enable indexing for dashboard links

* style: format with black

* fix: nudge index, don't enable

Many edge cases which can't be checked on-the-fly. Best to just notify
developer that they should enable indexing.

---------

Co-authored-by: Ankush Menat <[email protected]>
  • Loading branch information
barredterra and ankush authored Aug 3, 2023
1 parent d1c3877 commit fa73d5e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion frappe/core/doctype/doctype/doctype.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from frappe.modules import get_doc_path, make_boilerplate
from frappe.modules.import_file import get_file_path
from frappe.query_builder.functions import Concat
from frappe.utils import cint, flt, random_string
from frappe.utils import cint, flt, get_table_name, random_string
from frappe.website.utils import clear_cache

if TYPE_CHECKING:
Expand Down Expand Up @@ -198,6 +198,7 @@ def validate(self):
self.set("can_change_name_type", validate_autoincrement_autoname(self))
self.validate_document_type()
validate_fields(self)
self.check_indexing_for_dashboard_links()

if not self.istable:
validate_permissions(self)
Expand Down Expand Up @@ -298,6 +299,23 @@ def set_default_translatable(self):
if d.translatable and not supports_translation(d.fieldtype):
d.translatable = 0

def check_indexing_for_dashboard_links(self):
"""Enable indexing for outgoing links used in dashboard"""
for d in self.fields:
if d.fieldtype == "Link" and not (d.unique or d.search_index):
referred_as_link = frappe.db.exists(
"DocType Link",
{"parent": d.options, "link_doctype": self.name, "link_fieldname": d.fieldname},
)
if not referred_as_link:
continue

frappe.msgprint(
_("{0} should be indexed because it's referred in dashboard connections").format(_(d.label)),
alert=True,
indicator="orange",
)

def check_developer_mode(self):
"""Throw exception if not developer mode or via patch"""
if frappe.flags.in_patch or frappe.flags.in_test:
Expand Down

0 comments on commit fa73d5e

Please sign in to comment.