perf: Skip updating defaults when nothing has changed (#29036)
ERPNext updates defaults everytime settings are changed but there's no need to do it when value itself hasn't changed. IDK if there are things that depend on this weird behaviour, there shouldn't be any **ideally**. Feel free to revert if it breaks.
This commit is contained in:
parent
ded8cdfcb7
commit
00b3e05828
1 changed files with 8 additions and 4 deletions
|
|
@ -4,6 +4,7 @@
|
|||
import frappe
|
||||
from frappe.cache_manager import clear_defaults_cache, common_default_keys
|
||||
from frappe.query_builder import DocType
|
||||
from frappe.utils.data import cstr
|
||||
|
||||
# Note: DefaultValue records are identified by parent (e.g. __default, __global)
|
||||
|
||||
|
|
@ -154,14 +155,17 @@ def set_default(key, value, parent, parenttype="__default"):
|
|||
:param parent: Usually, **User** to whom the default belongs.
|
||||
:param parenttype: [optional] default is `__default`."""
|
||||
table = DocType("DefaultValue")
|
||||
key_exists = (
|
||||
current_value = (
|
||||
frappe.qb.from_(table)
|
||||
.where((table.defkey == key) & (table.parent == parent))
|
||||
.select(table.defkey)
|
||||
.select(table.defvalue)
|
||||
.for_update()
|
||||
.run()
|
||||
.run(as_dict=True)
|
||||
)
|
||||
if key_exists:
|
||||
if current_value:
|
||||
if current_value[0].defvalue == cstr(value):
|
||||
# Nothing has changed
|
||||
return
|
||||
frappe.db.delete("DefaultValue", {"defkey": key, "parent": parent})
|
||||
if value is not None:
|
||||
add_default(key, value, parent)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue