*: bus, hr_holidays. The `/bus/im_status` route polls the server every minute in order for the user im_status to be up to date. This commit removes this poll by sending the im_status on the bus when updating the current user presence. Moreover, before [1], the user bus presence was updated on each poll. When the user didn't poll for 50 seconds, we assumed the user was disconnected. Since [1], the bus presence is updated each 30 seconds by the `im_status` service. This is too frequent: there is no need to update the user presence so often. In order not to overhelm the server with unnecessary requests, the update presence interval as well as the delay to be considered disconnected have been updated: the former from 30 to 60 seconds, the later from 55 to 65 seconds (assuming that a user that has missed an update presence tick is disconnected). [1]: odoo/odoo@a5623d2 closes odoo/odoo#100249 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
29 lines
1.3 KiB
Python
29 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo import models, registry
|
|
from odoo.api import Environment
|
|
from odoo.fields import Datetime
|
|
from odoo.http import request
|
|
from odoo.addons.bus.websocket import wsrequest
|
|
|
|
class IrWebsocket(models.AbstractModel):
|
|
_inherit = 'ir.websocket'
|
|
|
|
def _update_bus_presence(self, inactivity_period, im_status_ids_by_model):
|
|
super()._update_bus_presence(inactivity_period, im_status_ids_by_model)
|
|
# This method can either be called due to an http or a
|
|
# websocket request. The request itself is necessary to
|
|
# retrieve the current guest. Let's retrieve the proper
|
|
# request.
|
|
req = request or wsrequest
|
|
if req.env.user._is_internal():
|
|
ip_address = req.httprequest.remote_addr
|
|
users_log = req.env['res.users.log'].search_count([
|
|
('create_uid', '=', req.env.user.id),
|
|
('ip', '=', ip_address),
|
|
('create_date', '>=', Datetime.to_string(Datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)))])
|
|
if not users_log:
|
|
with registry(req.env.cr.dbname).cursor() as cr:
|
|
env = Environment(cr, req.env.user.id, {})
|
|
env['res.users.log'].create({'ip': ip_address})
|