From 5c70cc24b3ce27ea28c19a53c1886720d56ca0d2 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 21 Jun 2018 15:02:30 +0200 Subject: [PATCH] [FIX] point_of_sale: performance improvement to read one session The fact the pos config name get was doing `config.session_ids[0].state` led to the prefetch of fields of all the session_ids of this config on reading `config_id` for the session form Therefore, if a pos config had 1000 sessions, it was prefetching fields of 1000 sessions when you actually wanted only one session to display in the form. Among others, the `picking_count` field which is not stored and quite heavy to compute In term of time, it went from 1 minute to 1 second to open the form view of one pos session. --- addons/point_of_sale/models/pos_config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index dac3f2f990b..0a9e76ac8ab 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -203,10 +203,11 @@ class PosConfig(models.Model): def name_get(self): result = [] for config in self: - if (not config.session_ids) or (config.session_ids[0].state == 'closed'): + last_session = self.env['pos.session'].search([('config_id', '=', config.id)], limit=1) + if (not last_session) or (last_session.state == 'closed'): result.append((config.id, config.name + ' (' + _('not used') + ')')) continue - result.append((config.id, config.name + ' (' + config.session_ids[0].user_id.name + ')')) + result.append((config.id, config.name + ' (' + last_session.user_id.name + ')')) return result @api.model