From cc7178b01976747178fdb0781a73132bcc6b5487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Tue, 26 Aug 2014 19:04:00 +0200 Subject: [PATCH] [FIX] bus, im_chat : disabled realtime status notification, replace it with rpc calls and set random retry delay on bus (longpolling) --- addons/bus/static/src/js/bus.js | 5 +++-- addons/im_chat/im_chat.py | 6 ++++-- addons/im_chat/static/src/js/im_chat.js | 10 ++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/addons/bus/static/src/js/bus.js b/addons/bus/static/src/js/bus.js index 34fae260a3a..91cf65d00e6 100644 --- a/addons/bus/static/src/js/bus.js +++ b/addons/bus/static/src/js/bus.js @@ -1,7 +1,7 @@ (function() { var bus = openerp.bus = {}; - bus.ERROR_DELAY = 30000; + bus.ERROR_DELAY = 10000; bus.Bus = openerp.Widget.extend({ init: function(){ @@ -24,7 +24,8 @@ _.each(result, _.bind(self.on_notification, self)); self.poll(); }, function(unused, e) { - setTimeout(_.bind(self.poll, self), bus.ERROR_DELAY); + // random delay to avoid massive longpolling + setTimeout(_.bind(self.poll, self), bus.ERROR_DELAY + (Math.floor((Math.random()*20)+1)*1000)); }); }, on_notification: function(notification) { diff --git a/addons/im_chat/im_chat.py b/addons/im_chat/im_chat.py index 0c60b64ba4b..46aa85cd4b1 100644 --- a/addons/im_chat/im_chat.py +++ b/addons/im_chat/im_chat.py @@ -328,8 +328,10 @@ class Controller(openerp.addons.bus.bus.Controller): if request.session.uid: registry, cr, uid, context = request.registry, request.cr, request.session.uid, request.context registry.get('im_chat.presence').update(cr, uid, ('im_presence' in options), context=context) - # listen to connection and disconnections - channels.append((request.db,'im_chat.presence')) + ## For performance issue, the real time status notification is disabled. This means a change of status are still braoadcasted + ## but not received by anyone. Otherwise, all listening user restart their longpolling at the same time and cause a 'ConnectionPool Full Error' + ## since there is not enought cursors for everyone. Now, when a user open his list of users, an RPC call is made to update his user status list. + ##channels.append((request.db,'im_chat.presence')) # channel to receive message channels.append((request.db,'im_chat.session', request.uid)) return super(Controller, self)._poll(dbname, channels, last, options) diff --git a/addons/im_chat/static/src/js/im_chat.js b/addons/im_chat/static/src/js/im_chat.js index 3ee54dbeddc..a6156f8f43c 100644 --- a/addons/im_chat/static/src/js/im_chat.js +++ b/addons/im_chat/static/src/js/im_chat.js @@ -471,8 +471,8 @@ $(window).resize(_.bind(this.calc_box, this)); this.calc_box(); - this.on("change:current_search", this, this.search_changed); - this.search_changed(); + this.on("change:current_search", this, this.search_users_status); + this.search_users_status(); // add a drag & drop listener self.c_manager.on("im_session_activated", self, function(conv) { @@ -505,7 +505,7 @@ input_change: function() { this.set("current_search", this.$(".oe_im_searchbox").val()); }, - search_changed: function(e) { + search_users_status: function(e) { var user_model = new openerp.web.Model("res.users"); var self = this; return this.user_search_dm.add(user_model.call("im_search", [this.get("current_search"), @@ -540,10 +540,12 @@ right: -this.$el.outerWidth(), }, opt); } else { - if (! openerp.bus.bus.activated) { + if (! openerp.bus.bus.activated) { this.do_warn("Instant Messaging is not activated on this server. Try later.", ""); return; } + // update the list of user status when show the IM + this.search_users_status(); this.$el.animate({ right: 0, }, opt);