Skip to content
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

[12.0][FIX] auditlog: Allow passing a chunk size for autovacuum #2335

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions auditlog/models/autovacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AuditlogAutovacuum(models.TransientModel):
_description = "Auditlog - Delete old logs"

@api.model
def autovacuum(self, days):
def autovacuum(self, days, chunk_size=None):
"""Delete all logs older than ``days``. This includes:
- CRUD logs (create, read, write, unlink)
- HTTP requests
Expand All @@ -31,9 +31,11 @@ def autovacuum(self, days):
)
for data_model in data_models:
records = self.env[data_model].search(
[('create_date', '<=', fields.Datetime.to_string(deadline))])
[('create_date', '<=', fields.Datetime.to_string(deadline))],
limit=chunk_size, order='create_date asc')
nb_records = len(records)
records.unlink()
with self.env.norecompute():
records.unlink()
_logger.info(
"AUTOVACUUM - %s '%s' records deleted",
nb_records, data_model)
Expand Down
4 changes: 4 additions & 0 deletions auditlog/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ To activate it and/or change the delay, go to the
`Auto-vacuum audit logs` entry:

.. image:: ../static/description/autovacuum.png

In case you're having trouble with the amount of records to delete per run,
you can pass the amount of records to delete for one model per run as the second
parameter, the default is to delete all records in one go.