-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADD] beesdoo_shift: next_shift_id on cooperative.status #273
Conversation
80c3cad
to
a6cf19d
Compare
def _compute_next_shift(self): | ||
now = fields.Datetime.now() | ||
for rec in self: | ||
rec.next_shift_id = self.env["beesdoo.shift.shift"].search( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search should be outside the loop, this kind of code is the root of performance issue
search worker_id in self.mapped('cooperator_id').ids and store the result in a dict
You will send only one query for instead of one for each record.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks. Something like this then ?
def _compute_next_shift(self):
now = fields.Datetime.now()
cooperator_ids = self.mapped("cooperator_id").ids
# avoid searching for shift in loop
next_shifts = self.env["beesdoo.shift.shift"].search(
[("start_time", ">=", now), ("worker_id", "in", cooperator_ids)],
order="worker_id, start_time",
)
next_shift_by_worker = {}
for shift in next_shifts:
# take fist shift for each worker
if shift.worker_id not in next_shift_by_worker:
next_shift_by_worker[shift.worker_id] = shift
for rec in self:
rec.next_shift_id = next_shift_by_worker[rec.cooperator_id]
Thanks for the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI Read the code (more for learning than a proper review :) )
e0ac974
to
e54d6d9
Compare
bb605b6
to
2aef4b6
Compare
d54907c
to
49ac63b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments. Looks good overall. Tests are 👌
903767d
to
32f927c
Compare
32f927c
to
f78d3a1
Compare
c6b4c08
to
07e2fd6
Compare
07e2fd6
to
18cba2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
18cba2e
to
104279b
Compare
I needed to add
shift_shift_ids
tores.partner
to trigger the computation. I hope it does not impact performance, maybe @tfrancoi knows.today
field ?is_subscribed_to_shift
computation since the `next_alert_date" is computed in overriding modules.task