[FIX] web: speedup basic_model._updateRecordsData

Speedup basic_model._updateRecordsData for
many2many fields such as fetchmail.server.message_ids
and mail_channel.channel_message_ids.

Calling _.findWhere(values) inside two nested _.each
calls can be quite slow when the number of values
is big.

Remove the call to _.findWhere by first
creating a Map res_id -> data and then calling
Map.get to retrieve the data for a given res_id
when making a DataPoint

opw-2701170

closes odoo/odoo#82540

X-original-commit: aaf653e744c846d4c399498ea38e358ddee80d4a
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Aurélien (avd)
2022-01-11 11:21:11 +00:00
parent 2192480ed1
commit 2c911fe176
@@ -5211,6 +5211,7 @@ var BasicModel = AbstractModel.extend({
var fieldsInfo = view ? view.fieldsInfo : fieldInfo.fieldsInfo;
var fields = view ? view.fields : fieldInfo.relatedFields;
var viewType = view ? view.type : fieldInfo.viewType;
var id2Values = new Map(values.map((value) => [value.id, value]))
_.each(records, function (record) {
var x2mList = self.localData[record.data[fieldName]];
@@ -5218,7 +5219,7 @@ var BasicModel = AbstractModel.extend({
_.each(x2mList.res_ids, function (res_id) {
var dataPoint = self._makeDataPoint({
modelName: field.relation,
data: _.findWhere(values, {id: res_id}),
data: id2Values.get(res_id),
fields: fields,
fieldsInfo: fieldsInfo,
parentID: x2mList.id,