Skip to content

[18.0][FIX] autovacuum_message_attachment: Add missing message_type 'auto_comment' and allow to batch deletion - #3665

Open
divad1196 wants to merge 3 commits into
OCA:18.0from
camptocamp:fix_vacuum_rule_message_type
Open

[18.0][FIX] autovacuum_message_attachment: Add missing message_type 'auto_comment' and allow to batch deletion#3665
divad1196 wants to merge 3 commits into
OCA:18.0from
camptocamp:fix_vacuum_rule_message_type

Conversation

@divad1196

@divad1196 divad1196 commented Jul 3, 2026

Copy link
Copy Markdown
  • auto_comment message_type was missing
    => Add the option
  • Deletion could timeout due to the number of records to delete
    => Added batch_size parameter to the rules
  • Optimization:
    • search performed orderby which forces an extra sort on the whole table
      => Use _search instead
    • unlink is batched by Odoo natively, and batch_unlink was also batching with its own value
      => Make them use the same limit and added a batch size parameter to batch_unlink

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @florian-dacosta,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added series:18.0 mod:autovacuum_message_attachment Module autovacuum_message_attachment labels Jul 3, 2026
@divad1196 divad1196 changed the title [FIX] Add missing message_type 'auto_comment' [18.0][FIX] autovacuum_message_attachment: Add missing message_type 'auto_comment' and allow to batch deletion Jul 3, 2026
@divad1196
divad1196 force-pushed the fix_vacuum_rule_message_type branch from 70113ae to e6088fe Compare July 3, 2026 13:54
@divad1196
divad1196 marked this pull request as ready for review July 3, 2026 13:54
@divad1196
divad1196 force-pushed the fix_vacuum_rule_message_type branch 2 times, most recently from 039f8aa to 9e35c6f Compare July 10, 2026 11:23
with Registry(self.env.cr.dbname).cursor() as new_cr:
if batch_size == -1:
batch_size = len(self)
if not batch_size or batch_size < 0:

@divad1196 divad1196 Jul 10, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: use if not batch_size or batch_size < new_cr.IN_MAX: instead

Done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO Still valid?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, change done

@simahawk simahawk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

with Registry(self.env.cr.dbname).cursor() as new_cr:
if batch_size == -1:
batch_size = len(self)
if not batch_size or batch_size < 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO Still valid?

@divad1196
divad1196 force-pushed the fix_vacuum_rule_message_type branch from 9e35c6f to 3b76be4 Compare August 3, 2026 08:26
with Registry(self.env.cr.dbname).cursor() as new_cr:
if batch_size == -1:
batch_size = len(self)
if not batch_size or batch_size < new_cr.IN_MAX:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not batch_size or batch_size < new_cr.IN_MAX:
if not batch_size:

Why not letting the option to the caller to have a batch size smaller than IN_MAX

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TDu Because a small batch size is almost never a good idea, especially due to IO and database query optimization.

On the other side, Odoo uses IN_MAX everywhere: If you had a reason to want smaller batch size, you would likely need it changes for the whole Odoo, not just the batch operations.


def batch_unlink(self):
def batch_unlink(self, batch_size=0):
# batch_size == -1 => delete everything in a single unlink (no chunking).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this option when it open the risk of Out Of Memory errors ?

Also mutating the IN_MAX value above a certain value is probably not recommended ! IMO

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not increase the risk of OOM, because little resources are allocated.
The GC will also not run between your batches, because your records are still referenced.
https://github.com/odoo/odoo/blob/03256802105c6273f62a5305d2395d7771418e0b/odoo/orm/models.py#L4232
https://github.com/odoo/odoo/blob/18.0/odoo/tools/misc.py#L692
On the other side, allowing to increase this limit reduces the risk of timeouts and idle transactions.

The max value acceptable for IN_MAX will depend on the context of the database. I was able to raise it to 1M on the customer database without issue, but it was not providing any performance improvment compared to batches of 50k.

@divad1196

Copy link
Copy Markdown
Author

@TDu I answered your questions. could you check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:autovacuum_message_attachment Module autovacuum_message_attachment series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants