[FIX] mail: avoid costly debug operations

These errors should not happen in production, it is only helpful for debugging.

The opportunity is taken to limit our debug code to a messaging specific debug,
as debug '1' is used in production to see extra features, and debug 'assets' is
necessary to get decent stack trace.

The easiest way to enable this debug mode at the time of this commit is to
either manually set the value to true in the code, or to type the following line
in the browser console if editing the code is not an option:
`odoo.__DEBUG__.messaging.modelManager.isDebug = true;`

Part of task-2702450

closes odoo/odoo#81075

X-original-commit: f9ae7510c8adaa83379b90f798ee535ede99be25
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
Sébastien Theys
2021-12-08 16:28:45 +00:00
parent bdb9ae8648
commit e1d3815348
5 changed files with 29 additions and 9 deletions
@@ -24,7 +24,7 @@
<i class="o_RtcOptionList_buttonIcon fa fa-lg fa-cog"/>
<span class="o_RtcOptionList_buttonText">Settings</span>
</button>
<t t-if="env.isDebug()">
<t t-if="messaging.modelManager.isDebug">
<button class="o_RtcOptionList_button" t-on-click="rtcOptionList.onClickDownloadLogs">
<i class="o_RtcOptionList_buttonIcon fa fa-lg fa-file-text-o"/>
<span class="o_RtcOptionList_buttonText">Download logs</span>
+7 -3
View File
@@ -569,7 +569,8 @@ export class ModelField {
* @returns {boolean} whether the value changed for the current field
*/
_setRelationLinkX2Many(record, newValue, { hasToUpdateInverse = true } = {}) {
const recordsToLink = this._convertX2ManyValue(newValue);
const hasToVerify = record.modelManager.isDebug;
const recordsToLink = this._convertX2ManyValue(newValue, { hasToVerify });
const otherRecords = this.read(record);
let hasChanged = false;
@@ -607,7 +608,9 @@ export class ModelField {
* @returns {boolean} whether the value changed for the current field
*/
_setRelationLinkX2One(record, recordToLink, { hasToUpdateInverse = true } = {}) {
this._verifyRelationalValue(recordToLink);
if (record.modelManager.isDebug) {
this._verifyRelationalValue(recordToLink);
}
const prevOtherRecord = this.read(record);
// other record already linked, avoid linking twice
if (prevOtherRecord === recordToLink) {
@@ -648,7 +651,8 @@ export class ModelField {
let hasToReorder = false;
const otherRecordsSet = this.read(record);
const otherRecordsList = [...otherRecordsSet];
const recordsToReplaceList = [...this._convertX2ManyValue(newValue)];
const hasToVerify = record.modelManager.isDebug;
const recordsToReplaceList = [...this._convertX2ManyValue(newValue, { hasToVerify })];
const recordsToReplaceSet = new Set(recordsToReplaceList);
// records to link
+12 -4
View File
@@ -98,6 +98,12 @@ export class ModelManager {
* and for which required fields check still has to be executed.
*/
this._updatedRecordsCheckRequired = new Set();
/**
* Determines whether this model manager should run in debug mode. Debug
* mode adds more integrity checks and more verbose error messages, at
* the cost of performance.
*/
this.isDebug = false;
}
/**
@@ -247,9 +253,11 @@ export class ModelManager {
if (!localId) {
return;
}
const modelName = localId.split('(')[0];
if (!isCheckingInheritance && modelName !== Model.name) {
throw Error(`wrong format of localId ${localId} for ${Model}.`);
if (!isCheckingInheritance && this.isDebug) {
const modelName = localId.split('(')[0];
if (modelName !== Model.name) {
throw Error(`wrong format of localId ${localId} for ${Model}.`);
}
}
for (const listener of this._listeners) {
listener.lastObservedLocalIds.add(localId);
@@ -667,7 +675,7 @@ export class ModelManager {
// Field values of record.
__values: {},
});
const record = !this.env.isDebug() ? nonProxyRecord : new Proxy(nonProxyRecord, {
const record = !this.isDebug ? nonProxyRecord : new Proxy(nonProxyRecord, {
get: function getFromProxy(record, prop) {
if (
!Model.__fieldMap[prop] &&
+1 -1
View File
@@ -357,7 +357,7 @@ registerModel({
* @param {String} [param2.state] current state of the connection
*/
_addLogEntry(token, entry, { error, step, state } = {}) {
if (!this.env.isDebug()) {
if (!this.modelManager.isDebug) {
return;
}
if (!(token in this.logs)) {
@@ -643,6 +643,14 @@ async function start(param0 = {}) {
loadingBaseDelayDuration,
messagingBus,
},
/**
* Override to ensure tests run in debug mode to catch all potential
* programming errors and provide better message when they happen.
*/
init(...args) {
this._super(...args);
this.modelManager.isDebug = true;
},
/**
* Override:
* - to ensure the test setup is complete before starting otherwise