[FIX] mail: optimize onChange by accessing reactive only once

Access `proxy[key]` only once to avoid triggering reactive `get()` many
times, as this will be triggered in cascade to all elements in the chain
in internal code, saving possibly dozens of uncessary calls per
callback.

Part-of: odoo/odoo#147814
This commit is contained in:
Sébastien Theys
2024-01-03 16:59:13 +00:00
parent 5fa9a3bf36
commit f0928cda55
2 changed files with 14 additions and 12 deletions
+7 -6
View File
@@ -1226,13 +1226,14 @@ export class Record {
static _onChange(record, key, callback) {
let proxy;
function _observe() {
void proxy[key];
if (proxy[key] instanceof Object) {
void Object.keys(proxy[key]);
// access proxy[key] only once to avoid triggering reactive get() many times
const val = proxy[key];
if (typeof val === "object" && val !== null) {
void Object.keys(val);
}
if (proxy[key] instanceof Array) {
void proxy[key].length;
void proxy[key].forEach((i) => i);
if (Array.isArray(val)) {
void val.length;
void val.forEach((i) => i);
}
}
if (Array.isArray(key)) {
+7 -6
View File
@@ -40,13 +40,14 @@ export function isDragSourceExternalFile(dataTransfer) {
export function onChange(target, key, callback) {
let proxy;
function _observe() {
void proxy[key];
if (proxy[key] instanceof Object) {
void Object.keys(proxy[key]);
// access proxy[key] only once to avoid triggering reactive get() many times
const val = proxy[key];
if (typeof val === "object" && val !== null) {
void Object.keys(val);
}
if (proxy[key] instanceof Array) {
void proxy[key].length;
void proxy[key].forEach((i) => i);
if (Array.isArray(val)) {
void val.length;
void val.forEach((i) => i);
}
}
if (Array.isArray(key)) {