Writing frequently to master data, and particularly to res.users records is dangerous because it can temporarily delay/abort concurrent transactions due to FK locking/serializability heuristics. (Even with PostgreSQL 9.3+) The `login_date` field updated when a user is authentiocated is still useful but better handled in a separate table that exclusively receives independent INSERTs (no UPDATE/DELETE). This minimizes the chances of transactional conflicts. This commit moves the login_date info into a separate `res.users.log` table for this purpose, replacing it with a related field. The user and login date info are automatically handled by the magical fields (create_uid, create_date) in `res.users.log`. The related field must not be stored because that would create the same problems as the original field. In order to cleanup redundant entries in res.users.log the 'auto-vacuum' cron job used for TransientModels was extended to be a generic "internal data vacuum cleaner", and now takes care of this as well. The code for updating last login and vacuuming was split up into smaller methods to make extensions easier. Fixes #8585 Fixes #8590
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from openerp import http
|
|
from openerp.http import request
|
|
|
|
|
|
class WebSettingsDashboard(http.Controller):
|
|
|
|
@http.route('/web_settings_dashboard/data', type='json', auth='user')
|
|
def web_settings_dashboard_data(self, **kw):
|
|
|
|
installed_apps = request.env['ir.module.module'].search_count([
|
|
('application', '=', True),
|
|
('state', 'in', ['installed', 'to upgrade', 'to remove'])
|
|
])
|
|
active_users = request.env['res.users'].search_count([('active', '=', True), ('log_ids', '!=', False)])
|
|
pending_users = request.env['res.users'].search([('log_ids', '=', False)], order="create_date desc")
|
|
|
|
return {
|
|
'apps': {
|
|
'installed_apps': installed_apps
|
|
},
|
|
'users_info': {
|
|
'active_users': active_users,
|
|
'pending_users': zip(pending_users.mapped('id'), pending_users.mapped('login')),
|
|
'user_form_view_id': request.env['ir.model.data'].xmlid_to_res_id("base.view_users_form"),
|
|
},
|
|
}
|