Merge pull request #35000 from sagarvora/perf-validate-link

perf: ignore link validation if no fetch and value in awesomplete list
This commit is contained in:
Sagar Vora 2025-12-01 21:23:21 +05:30 committed by GitHub
commit e3e5b6616a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View file

@ -108,7 +108,6 @@ context("Control Link", () => {
it("should show open link button", () => {
get_dialog_with_link().as("dialog");
cy.intercept("/api/method/frappe.client.validate_link*").as("validate_link");
cy.intercept("POST", "/api/method/frappe.desk.search.search_link").as("search_link");
cy.get("@todos").then((todos) => {
@ -116,7 +115,7 @@ context("Control Link", () => {
cy.get("@input").focus();
cy.wait("@search_link");
cy.get("@input").type(todos[0]).blur();
cy.wait("@validate_link");
// not waiting for validate_link because it will not get called
cy.get("@input").trigger("mouseover");
cy.get(".frappe-control[data-fieldname=link] .btn-open")
.should("be.visible")

View file

@ -6,6 +6,7 @@
// add_fetches
import Awesomplete from "awesomplete";
frappe.ui.form.recent_link_validations = {};
const SPECIAL_VALUES = ["create_new__link_option", "advanced_search__link_option"];
frappe.ui.form.ControlLink = class ControlLink extends frappe.ui.form.ControlData {
static trigger_change_on_input_event = false;
@ -663,9 +664,20 @@ frappe.ui.form.ControlLink = class ControlLink extends frappe.ui.form.ControlDat
}
const columns_to_fetch = Object.values(this.fetch_map);
const nothing_to_fetch = !columns_to_fetch.length;
// if default and no fetch, no need to validate
if (!columns_to_fetch.length && this.df.__default_value === value) {
if (nothing_to_fetch && this.df.__default_value === value) {
return value;
}
if (
nothing_to_fetch &&
value &&
!SPECIAL_VALUES.includes(value) &&
this.awesomplete.get_item(value)
) {
// if value is in the suggestion list, must be correct
return value;
}