Merge pull request #41871 from blaggacao/perf/reduce-critical-path

perf: hot path in page load
This commit is contained in:
David Arnold
2024-09-05 15:50:23 +02:00
committed by GitHub
4 changed files with 90 additions and 64 deletions

View File

@@ -424,7 +424,7 @@ $.extend(erpnext.utils, {
});
},
get_fiscal_year: function (date, with_dates = false, boolean = false) {
get_fiscal_year: function (date, with_dates = false, raise_on_missing = true) {
if (!frappe.boot.setup_complete) {
return;
}
@@ -433,20 +433,30 @@ $.extend(erpnext.utils, {
}
let fiscal_year = "";
frappe.call({
method: "erpnext.accounts.utils.get_fiscal_year",
args: {
date: date,
boolean: boolean,
},
async: false,
callback: function (r) {
if (r.message) {
if (with_dates) fiscal_year = r.message;
else fiscal_year = r.message[0];
}
},
});
if (
frappe.boot.current_fiscal_year &&
date >= frappe.boot.current_fiscal_year[1] &&
date <= frappe.boot.current_fiscal_year[2]
) {
if (with_dates) fiscal_year = frappe.boot.current_fiscal_year;
else fiscal_year = frappe.boot.current_fiscal_year[0];
} else {
frappe.call({
method: "erpnext.accounts.utils.get_fiscal_year",
type: "GET", // make it cacheable
args: {
date: date,
raise_on_missing: raise_on_missing,
},
async: false,
callback: function (r) {
if (r.message) {
if (with_dates) fiscal_year = r.message;
else fiscal_year = r.message[0];
}
},
});
}
return fiscal_year;
},
});