From 89112f8ecf7d166e6a8382a4fff57beab490ab74 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 31 Mar 2022 11:16:10 +0000 Subject: [PATCH] [IMP] mail: do not call getViews for chatter fields Before this commit, in form views, a call to "getViews" was done for each field in the div with className "oe_chatter" (i.e. "message_ids", "message_follower_ids" and "activity_ids"). Those calls were unnecessary since those fields are displayed with a custom widget (the Chatter) anyway. Part-of: odoo/odoo#87522 --- addons/mail/static/src/js/basic_view.js | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/addons/mail/static/src/js/basic_view.js b/addons/mail/static/src/js/basic_view.js index 82e2b836f5b..aaaf356734b 100644 --- a/addons/mail/static/src/js/basic_view.js +++ b/addons/mail/static/src/js/basic_view.js @@ -4,6 +4,8 @@ import BasicView from 'web.BasicView'; const mailWidgets = ['kanban_activity']; +const chatterFields = ["message_ids", "message_follower_ids", "activity_ids"]; + BasicView.include({ init: function () { this._super.apply(this, arguments); @@ -62,4 +64,29 @@ BasicView.include({ _hasField(fieldName) { return !!this.fieldsInfo[this.viewType][fieldName]; }, + /** + * Override to mark chatter fields inside the "oe_chatter" div such that we + * don't fetch their sub views, as we don't need them. Without this, those + * subviews would be loaded as there is no "widget" set on those fields. + * + * @override + */ + _processNode(node, fv) { + if (node.tag === "div" && node.attrs.class && node.attrs.class.includes("oe_chatter")) { + const viewType = fv.type; + const fieldsInfo = fv.fieldsInfo[viewType]; + const fields = fv.viewFields; + for (const child of node.children) { + if (child.tag === 'field' && chatterFields.includes(child.attrs.name)) { + const attrs = { ...child.attrs, modifiers: {}, __no_fetch: true }; + const fieldName = attrs.name; + fieldsInfo[fieldName] = this._processField(viewType, fields[fieldName], attrs); + } else { + this._processNode(child, fv); + } + } + return false; + } + return this._super(...arguments); + }, });