From 379a67e6dee4fe45c94e544ff31415d4c963348e Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 6 Oct 2022 11:18:45 +0000 Subject: [PATCH] [FIX] web_editor: cache editor name_search/read across multiple m2o The RPC that the m2o widgets used by snippet options make are cached at the widget level. When two m2o widgets make the same RPC, they are indeed made twice. This commit just move the cache outside of the widget instance and thus makes it so the same RPC made across multiple m2o are cached. Note: this was particularly visible because all main snippets have the "Conditional Visibility" option which uses 3 m2m widgets. At each drop of such main snippet in the page, the option is created and the 3 m2m widgets made their RPC. Then each further drop of snippet made the exact same RPC for no good reason. In the future, the system should be further improved to not require those RPC on initial drop and clicks, especially as the "Conditional Visibility" m2m widgets are hidden by default. This fix focuses on fixing the generic m2m widgets. closes odoo/odoo#102800 X-original-commit: 8e08c896df9ed5a7a0e559f1dbd8812f87908a39 Signed-off-by: Quentin Smetz (qsm) --- addons/web_editor/static/src/js/editor/snippets.options.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index e88900cbc57..299aed15649 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -2465,6 +2465,7 @@ const SelectPagerUserValueWidget = SelectUserValueWidget.extend({ }, }); +const m2oRpcCache = {}; const Many2oneUserValueWidget = SelectUserValueWidget.extend({ className: (SelectUserValueWidget.prototype.className || '') + ' o_we_many2one', events: Object.assign({}, SelectUserValueWidget.prototype.events, { @@ -2482,7 +2483,7 @@ const Many2oneUserValueWidget = SelectUserValueWidget.extend({ init(parent, title, options, $target) { this.afterSearch = []; this.displayNameCache = {}; - this._rpcCache = {}; + this._rpcCache = m2oRpcCache; const {dataAttributes} = options; Object.assign(options, { limit: '5',