perf: Make request for filters_config once

Prior to this, a request was made on every filter change for a
filters_config entry. The options would not change based on the List /
filters context since no such data is shared with the API. Hence, it
can be stored upon first request for re-use.

Eg: Current usage in ERPNext - fiscal year operator's options don't change
frequently.
This commit is contained in:
gavin 2022-05-27 14:24:21 +05:30
parent e6460b2930
commit c9504f3bfc

View file

@ -249,14 +249,21 @@ frappe.ui.Filter = class {
const filter_value = this.filter_list.get_filter_value(fieldname);
args[field_name] = filter_value;
}
frappe
.xcall(this.filters_config[condition].get_field, args)
.then(field => {
df.fieldtype = field.fieldtype;
df.options = field.options;
df.fieldname = fieldname;
this.make_field(df, cur.fieldtype);
let setup_field = (field) => {
df.fieldtype = field.fieldtype;
df.options = field.options;
df.fieldname = fieldname;
this.make_field(df, cur.fieldtype);
}
if (this.filters_config[condition].data) {
let field = this.filters_config[condition].data;
setup_field(field);
} else {
frappe.xcall(this.filters_config[condition].get_field, args).then(field => {
this.filters_config[condition].data = field;
setup_field(field);
});
}
} else {
this.make_field(df, cur.fieldtype);
}