Daily updates from Odoo
Wednesday, July 3, 2024
1 change
Resolved issues and error corrections
This fix resolves a memory error that occurred when helpdesk teams had large numbers of tickets (60,000+). The system was performing inefficient queries that consumed excessive memory. The update optimizes the code to use a more efficient search method, dramatically reducing the number of database queries and improving system stability for customers with high ticket volumes.
Original PR description
**Traceback:** ```python ('helpdesk.helpdesk_team_menu', 393, 'Helpdesk > Configuration > Helpdesk Teams', 559): Traceback (most recent call last): File…
**Traceback:**
```python
('helpdesk.helpdesk_team_menu', 393, 'Helpdesk > Configuration > Helpdesk Teams', 559):
Traceback (most recent call last):
File "/tmp/tmpkjz256np/migrations/base/tests/test_mock_crawl.py", line 255, in crawl_menu
self.mock_action(action_vals)
File "/tmp/tmpkjz256np/migrations/base/tests/test_mock_crawl.py", line 412, in mock_action
mock_method(model, view, fields_list, domain, group_by)
File "/tmp/tmpkjz256np/migrations/base/tests/test_mock_crawl.py", line 441, in mock_view_form
[data] = record.read(fields_list)
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 3540, in read
return self._read_format(fnames=fields, load=load)
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 3751, in _read_format
vals[name] = convert(record[name], record, use_display_name)
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 6631, in __getitem__
return self._fields[key].__get__(self, self.env.registry[self._name])
File "/home/odoo/src/odoo/17.0/odoo/fields.py", line 1207, in __get__
self.compute_value(recs)
File "/home/odoo/src/odoo/17.0/odoo/fields.py", line 1389, in compute_value
records._compute_field_value(self)
File "/home/odoo/src/odoo/17.0/addons/mail/models/mail_thread.py", line 424, in _compute_field_value
return super()._compute_field_value(field)
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 4875, in _compute_field_value
fields.determine(field.compute, self)
File "/home/odoo/src/odoo/17.0/odoo/fields.py", line 102, in determine
return needle(*args)
File "/home/odoo/src/enterprise/17.0/helpdesk_timesheet/models/helpdesk_team.py", line 22, in _compute_total_timesheet_time
[('helpdesk_ticket_id', 'in', helpdesk_timesheet_teams.ticket_ids.filtered(lambda x: not x.stage_id.fold).ids)],
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 6110, in filtered
return self.browse([rec.id for rec in self if func(rec)])
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 6110, in <listcomp>
return self.browse([rec.id for rec in self if func(rec)])
File "/home/odoo/src/enterprise/17.0/helpdesk_timesheet/models/helpdesk_team.py", line 22, in <lambda>
[('helpdesk_ticket_id', 'in', helpdesk_timesheet_teams.ticket_ids.filtered(lambda x: not x.stage_id.fold).ids)],
File "/home/odoo/src/odoo/17.0/odoo/fields.py", line 2907, in __get__
return super().__get__(records, owner)
File "/home/odoo/src/odoo/17.0/odoo/fields.py", line 1182, in __get__
recs._fetch_field(self)
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 3777, in _fetch_field
self.fetch(fnames)
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 3827, in fetch
fetched = self._fetch_query(query, fields_to_fetch)
File "/home/odoo/src/odoo/17.0/odoo/models.py", line 3920, in _fetch_query
rows = self.env.cr.fetchall()
MemoryError
```
**Summary of changes:**
Previously, the code `helpdesk_timesheet_teams.ticket_ids.filtered( lambda x: not x.stage_id.fold).ids)` generating O(n) queries leading to a memory error when dealing with large numbers of tickets (e.g., 60k+ for this customer).
This commit refactors the code to use the search method instead. this approach reduces the number of queries to O(1) and significantly improves performance for customers with a large number of helpdesk tickets.
UPG - [1776915](https://upgrade.odoo.com/web#id=1776915&cids=1&menu_id=107&action=150&model=upgrade.request&view_type=form)
TASK - [3995988](https://www.odoo.com/odoo/my-tasks/3995988?cids=2)