From 693c771111eb7fa6edaaa36bb86f3df64cc6b9ba Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 25 Apr 2018 12:25:45 +0200 Subject: [PATCH] [IMP] web: abord the poll when destroy to avoid useless call If the service bus are called and destroyed the rpc can be returned after, to avoid a useless call to the database and unexpected behavior, we abort the connection. --- addons/bus/static/src/js/bus.js | 6 +++++- addons/web/static/src/js/core/service_mixins.js | 6 ++++-- addons/web/static/src/js/core/session.js | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/bus/static/src/js/bus.js b/addons/bus/static/src/js/bus.js index d0da7676f9f..bf5bb5277be 100644 --- a/addons/bus/static/src/js/bus.js +++ b/addons/bus/static/src/js/bus.js @@ -53,6 +53,7 @@ bus.Bus = Widget.extend({ }, destroy: function () { var self = this; + this.stop_polling(); $(window).off("focus." + this.bus_id); $(window).off("blur." + this.bus_id); $(window).off("unload." + this.bus_id); @@ -70,6 +71,9 @@ bus.Bus = Widget.extend({ this.activated = false; this.stop = true; this.channels = []; + if (this._pollRpc) { + this._pollRpc.abort(); + } }, poll: function () { var self = this; @@ -89,7 +93,7 @@ bus.Bus = Widget.extend({ this._pollRpc.then(function (result) { self._pollRpc = false; self.on_notification(result); - if (!self.stop) { + if (!self.stop && self.activated) { self.poll(); } }, function (error, event) { diff --git a/addons/web/static/src/js/core/service_mixins.js b/addons/web/static/src/js/core/service_mixins.js index d1868c98d1f..850e9983a74 100644 --- a/addons/web/static/src/js/core/service_mixins.js +++ b/addons/web/static/src/js/core/service_mixins.js @@ -127,8 +127,10 @@ var ServicesMixin = { */ _rpc: function (params, options) { var query = rpc.buildQuery(params); - var def = this.call('ajax', 'rpc', query.route, query.params, options); - return def ? def.promise() : $.Deferred().promise(); + var def = this.call('ajax', 'rpc', query.route, query.params, options) || $.Deferred(); + var promise = def.promise(); + promise.abort = def.abort ? def.abort.bind(def) : function abort () {def.reject();}; + return promise; }, loadFieldView: function (dataset, view_id, view_type, options) { return this.loadViews(dataset.model, dataset.get_context().eval(), [[view_id, view_type]], options).then(function (result) { diff --git a/addons/web/static/src/js/core/session.js b/addons/web/static/src/js/core/session.js index 09b65357404..fcbc5872be0 100644 --- a/addons/web/static/src/js/core/session.js +++ b/addons/web/static/src/js/core/session.js @@ -346,7 +346,9 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, { return deferred.then(function () { if (aborted) { - return $.Deferred().reject('communication', $.Event(), 'abort', 'abort'); + var def = $.Deferred().reject('communication', $.Event(), 'abort', 'abort'); + def.abort = function () {}; + return def; } // TODO: remove if (! _.isString(url)) {