diff options
| author | Aaron Bohy <aab@odoo.com> | 2018-02-06 08:21:56 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-02-07 08:49:58 +0100 |
| commit | 7937347d756c0b8bf58ca9c01de24f96d87ffd18 (patch) | |
| tree | f79e7ff41f81dedc6fe6f3e39ab12ad574664e2a /addons/web/static/src | |
| parent | 20f2de82965ed782f14f4154f750853ae5c297f8 (diff) | |
[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.
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 37 |
1 files changed, 34 insertions, 3 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 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 @@ -2938,6 +2954,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 * in the modifiers, and if there is no readonly modifier, checking the |
