Skip to content
Snippets Groups Projects
user avatar
PermanAtayev authored
When there are many `calendar.event`s (700K+), MemoryError happens when they are tried to be sorted
before returning them in `get_recurrent_ids` method.

[upg-377987](https://upgrade.odoo.com/web#action=150&cids=1&id=377987&menu_id=107&model=upgrade.request&view_type=form)
Traceback from the upgrade request:
```
Traceback (most recent call last):
  File "/home/odoo/src/odoo/12.0/odoo/addons/base/maintenance/migrations/base/tests/test_mock_crawl.py", line 220, in crawl_menu
    self.mock_action(action_vals)
  File "/home/odoo/src/odoo/12.0/odoo/addons/base/maintenance/migrations/base/tests/test_mock_crawl.py", line 347, in mock_action
    mock_method(model, view, fields_list, domain, group_by)
  File "/home/odoo/src/odoo/12.0/odoo/addons/base/maintenance/migrations/base/tests/test_mock_crawl.py", line 368, in mock_view_form
    records = model.search(domain, limit=3)
  File "/home/odoo/src/odoo/12.0/odoo/models.py", line 1581, in search
    res = self._search(args, offset=offset, limit=limit, order=order, count=count)
  File "/home/odoo/src/odoo/12.0/addons/calendar/models/calendar.py", line 1802, in _search
    events = self.browse(events.get_recurrent_ids(args, order=order))
  File "/home/odoo/src/odoo/12.0/addons/calendar/models/calendar.py", line 1261, in get_recurrent_ids
    return [r['id'] for r in sorted(result_data, key=key)]
  File "/home/odoo/src/odoo/12.0/addons/calendar/models/calendar.py", line 1259, in key
    for v, desc in vals_spec
  File "/home/odoo/src/odoo/12.0/addons/calendar/models/calendar.py", line 1259, in <listcomp>
    for v, desc in vals_spec
MemoryError

The issue is happening in the `key` function when data is being sorted before returning it. In this function to compare events for every key a list is returned.
Returning a list for every element leads to a memory error because lists over allocate memory when they are created to make Time complexity of [appending to a list O(1) in amortized time](https://stackoverflow.com/questions/46664007/why-do-tuples-take-less-space-in-memory-than-lists

)
Over allocating memory a few times would not be a problem but given that this db has 700K+ `calendar.events`, over allocation causes a memory error. That's why it is better
to return tuples instead of lists, which do not over allocate because they are immutable, which will resolve the MemoryError.

closes odoo/odoo#103182

X-original-commit: c53081f1
Signed-off-by: default avatarChristophe Simonis <chs@odoo.com>
527fc34c
History

Build Status Tech Doc Help Nightly Builds

Odoo

Odoo is a suite of web based open source business apps.

The main Odoo Apps include an Open Source CRM, Website Builder, eCommerce, Warehouse Management, Project Management, Billing & Accounting, Point of Sale, Human Resources, Marketing, Manufacturing, ...

Odoo Apps can be used as stand-alone applications, but they also integrate seamlessly so you get a full-featured Open Source ERP when you install several Apps.

Getting started with Odoo

For a standard installation please follow the Setup instructions from the documentation.

To learn the software, we recommend the Odoo eLearning, or Scale-up, the business game. Developers can start with the developer tutorials