[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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user