From 7937347d756c0b8bf58ca9c01de24f96d87ffd18 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 6 Feb 2018 08:21:56 +0100 Subject: [IMP] web: invalidate JS cache for some models Models concerned are 'ir.ui.view', 'ir.actions.act_window' and 'ir.filters'. The DataManager's cache is invalidated at each create, update and unlink operation. This cache stores actions (results of calls to /web/action/load route), views (results of load_views RPCs) and filters (fetched alonside views). This rev. thus spares the user from reloading the webclient after performing such operations on these models to see the changes in the interface, as he only has to replay the action to see the changes. --- .../web/static/src/js/views/basic/basic_model.js | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 90854bc577e..b8970a2ec89 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -134,6 +134,14 @@ var x2ManyCommands = { }; var BasicModel = AbstractModel.extend({ + // list of models for which the DataManager's cache should be cleared on + // create, update and delete operations + noCacheModels: [ + 'ir.actions.act_window', + 'ir.filters', + 'ir.ui.view', + ], + /** * @override */ @@ -248,6 +256,8 @@ var BasicModel = AbstractModel.extend({ record.count--; } }); + // optionally clear the DataManager's cache + self._invalidateCache(records[0]); }); }, /** @@ -909,11 +919,14 @@ var BasicModel = AbstractModel.extend({ // Erase changes as they have been applied record._changes = {}; + // Optionally clear the DataManager's cache + self._invalidateCache(record); + self.unfreezeOrder(record.id); // Update the data directly or reload them if (shouldReload) { - self._fetchRecord(record).then(function (record) { + self._fetchRecord(record).then(function () { def.resolve(changedFields); }); } else { @@ -1023,8 +1036,11 @@ var BasicModel = AbstractModel.extend({ method: 'write', args: [resIDs, { active: value }], }) - .then(this.reload.bind(this, parentID)); - + .then(function () { + // optionally clear the DataManager's cache + self._invalidateCache(parent); + return self.reload(parentID); + }); }, /** * Toggle (open/close) a group in a grouped list, then fetches relevant @@ -2937,6 +2953,21 @@ var BasicModel = AbstractModel.extend({ } return context; }, + /** + * Invalidates the DataManager's cache if the main model (i.e. the model of + * its root parent) of the given dataPoint is a model in 'noCacheModels'. + * + * @private + * @param {Object} dataPoint + */ + _invalidateCache: function (dataPoint) { + while (dataPoint.parentID) { + dataPoint = this.localData[dataPoint.parentID]; + } + if (_.contains(this.noCacheModels, dataPoint.model)) { + core.bus.trigger('clear_cache'); + } + }, /** * Returns true if the field is protected against changes, looking for a * readonly modifier unless there is a force_save modifier (checking first -- cgit v1.2.3