[IMP] event(_*): limit usage of search
Purpose of this commit is to globally improve code performance by limiting search impact by * adding limits when only first found record id used; * avoid unnecessary searches when record set can be filtered instead; Task-2638444 PR odoo/odoo#76005 Co-Authored-By: Thibault Delavallée <tde@odoo.com> Co-Authored-By: Victor Feyens <vfe@odoo.com>
This commit is contained in:
co-authored by
Victor Feyens
parent
d875bcd79d
commit
2f4d582a79
@@ -88,8 +88,7 @@ class EventEvent(models.Model):
|
||||
_order = 'date_begin'
|
||||
|
||||
def _get_default_stage_id(self):
|
||||
event_stages = self.env['event.stage'].search([])
|
||||
return event_stages[0] if event_stages else False
|
||||
return self.env['event.stage'].search([], limit=1)
|
||||
|
||||
def _default_description(self):
|
||||
return self.env['ir.ui.view']._render_template('event.event_default_descripton')
|
||||
@@ -574,9 +573,9 @@ class EventEvent(models.Model):
|
||||
into the first next (by sequence) stage defined as "Ended"
|
||||
(if they are not already in an ended stage)
|
||||
"""
|
||||
first_ended_stage = self.env['event.stage'].search([('pipe_end', '=', True)], order='sequence')
|
||||
first_ended_stage = self.env['event.stage'].search([('pipe_end', '=', True)], limit=1, order='sequence')
|
||||
if first_ended_stage:
|
||||
self.write({'stage_id': first_ended_stage[0].id})
|
||||
self.write({'stage_id': first_ended_stage.id})
|
||||
|
||||
def mail_attendees(self, template_id, force_send=False, filter_func=lambda self: self.state != 'cancel'):
|
||||
for event in self:
|
||||
|
||||
@@ -5,7 +5,6 @@ from ast import literal_eval
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import fields, models, _
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
class EventLeadRule(models.Model):
|
||||
@@ -205,10 +204,7 @@ class EventLeadRule(models.Model):
|
||||
"""
|
||||
self.ensure_one()
|
||||
if self.event_registration_filter and self.event_registration_filter != '[]':
|
||||
registrations = registrations.search(expression.AND([
|
||||
[('id', 'in', registrations.ids)],
|
||||
literal_eval(self.event_registration_filter)
|
||||
]))
|
||||
registrations = registrations.filtered_domain(literal_eval(self.event_registration_filter))
|
||||
|
||||
# check from direct m2o to linked m2o / o2m to filter first without inner search
|
||||
company_ok = lambda registration: registration.company_id == self.company_id if self.company_id else True
|
||||
|
||||
Reference in New Issue
Block a user