summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/views')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js35
1 files changed, 29 insertions, 6 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index 7797abfc3f6..a664344ddf5 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -1421,11 +1421,13 @@ var BasicModel = AbstractModel.extend({
}
// avoid rpc if not necessary
- var specialDataCache = {context: context, domain: domain};
- if (_.isEqual(record._specialDataCache[fieldName], specialDataCache)) {
+ var hasChanged = this._saveSpecialDataCache(record, fieldName, {
+ context: context,
+ domain: domain,
+ });
+ if (!hasChanged) {
return $.when();
}
- record._specialDataCache[fieldName] = specialDataCache;
var self = this;
return this._rpc(field.relation, 'search_read')
@@ -1472,11 +1474,13 @@ var BasicModel = AbstractModel.extend({
var domain = record.getDomain({fieldName: fieldName});
// avoid rpc if not necessary
- var specialDataCache = {context: context, domain: domain};
- if (_.isEqual(record._specialDataCache[fieldName], specialDataCache)) {
+ var hasChanged = this._saveSpecialDataCache(record, fieldName, {
+ context: context,
+ domain: domain,
+ });
+ if (!hasChanged) {
return $.when();
}
- record._specialDataCache[fieldName] = specialDataCache;
return this._rpc(field.relation, "name_search")
.args(["", domain])
@@ -2141,6 +2145,25 @@ var BasicModel = AbstractModel.extend({
});
},
/**
+ * Allows to save a value in the specialData cache associated to a given
+ * record and fieldName. If the value in the cache was already the given
+ * one, nothing is done and the method indicates it by returning false
+ * instead of true.
+ *
+ * @private
+ * @param {Object} record - an element from the localData
+ * @param {string} fieldName - the name of the field
+ * @param {*} value - the cache value to save
+ * @returns {boolean} false if the value was already the given one
+ */
+ _saveSpecialDataCache: function (record, fieldName, value) {
+ if (_.isEqual(record._specialDataCache[fieldName], value)) {
+ return false;
+ }
+ record._specialDataCache[fieldName] = value;
+ return true;
+ },
+ /**
* Do a /search_read to get data for a list resource. This does a
* /search_read because the data may not be static (for ex, a list view).
*