Skip to content

Commit

Permalink
[FIX] auditlog: Allow passing a chunk size for autovacuum
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed May 11, 2022
1 parent 11b6cfd commit d4f8eb3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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.

0 comments on commit d4f8eb3

Please sign in to comment.