From 0359da630159b0a318ee5cbd3869030c3bd10469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Thu, 16 Nov 2023 11:08:24 +0100 Subject: [PATCH] [FIX] model: don't flatten command result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `array.flat()` is slow because it creates a new array (and allocates memory) With this commit, we only execute `array.flat()` if the command as been refused by one of the plugins (for possibly several resons) `checkDispatchAllowed` self-time could take up to 4% of the total time when loading a spreadsheet with lots of initial revisions. Now it's 0.0% :) closes odoo/o-spreadsheet#3195 X-original-commit: 4991b29b349e78af6045cd30be10e60238f17d15 Signed-off-by: Rémi Rahir (rar) Signed-off-by: Lucas Lefèvre (lul) --- src/model.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/model.ts b/src/model.ts index 5f2169bd76..76f1439bfb 100644 --- a/src/model.ts +++ b/src/model.ts @@ -429,7 +429,10 @@ export class Model extends EventBus implements CommandDispatcher { */ private checkDispatchAllowed(command: Command): DispatchResult { const results = this.handlers.map((handler) => handler.allowDispatch(command)); - return new DispatchResult(results.flat()); + if (results.some((r) => r !== CommandResult.Success)) { + return new DispatchResult(results.flat()); + } + return DispatchResult.Success; } private finalize() {