From 52c986ed193d57b8f3a08174ca987135d1335f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Tue, 5 Mar 2024 14:19:53 +0100 Subject: [PATCH] [PERF] spreadsheet: avoid useless evaluation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - create a relational filter, let's say on `res.company` - add a default value - reference the filter in a cell with `=ODOO.FILTER.VALUE("my filter")` => every `ODOO.FILTER.VALUE` triggers an evaluation With this commit, the re-evaluation after the data is fetched uses the data source mechanism which only re-evaluates when all the data promises are resolved, instead of evaluating after every resolved promise. With this commit, the number of evaluations required when loading the Timesheet report on our prod goes from 5 evaluations to only 3 (each evaluation is 2-3s) because `ODOO.FILTER.VALUE("Company")` is present two times. One issue this commit doesn't fix: there one RPC per `ODOO.FILTER.VALUE` (can be fixed in master very easily because we refactored data fetching) closes odoo/odoo#156495 Task: 3787125 Signed-off-by: Rémi Rahir (rar) --- .../src/global_filters/plugins/global_filters_ui_plugin.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/spreadsheet/static/src/global_filters/plugins/global_filters_ui_plugin.js b/addons/spreadsheet/static/src/global_filters/plugins/global_filters_ui_plugin.js index a7f658f10dd..ee09e77349f 100644 --- a/addons/spreadsheet/static/src/global_filters/plugins/global_filters_ui_plugin.js +++ b/addons/spreadsheet/static/src/global_filters/plugins/global_filters_ui_plugin.js @@ -49,6 +49,7 @@ export class GlobalFiltersUIPlugin extends spreadsheet.UIPlugin { constructor(config) { super(config); this.orm = config.custom.env?.services.orm; + this.dataSources = config.custom.dataSources; this.user = config.custom.env?.services.user; /** * Cache record display names for relation filters. @@ -271,15 +272,13 @@ export class GlobalFiltersUIPlugin extends spreadsheet.UIPlugin { return [[{ value: "" }]]; } if (!this.recordsDisplayName[filter.id]) { - this.orm + const promise = this.orm .call(filter.modelName, "read", [value, ["display_name"]]) .then((result) => { const names = result.map(({ display_name }) => display_name); this.recordsDisplayName[filter.id] = names; - this.dispatch("EVALUATE_CELLS", { - sheetId: this.getters.getActiveSheetId(), - }); }); + this.dataSources.notifyWhenPromiseResolves(promise); return [[{ value: "" }]]; } return [[{ value: this.recordsDisplayName[filter.id].join(", ") }]];