From d4f8eb345acfb60d7ff28180614340944c03225e Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 10 May 2022 13:00:13 +0200 Subject: [PATCH] [FIX] auditlog: Allow passing a chunk size for autovacuum --- auditlog/models/autovacuum.py | 8 +++++--- auditlog/readme/CONFIGURE.rst | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/auditlog/models/autovacuum.py b/auditlog/models/autovacuum.py index b3770ed63c8..8fb996a9efb 100644 --- a/auditlog/models/autovacuum.py +++ b/auditlog/models/autovacuum.py @@ -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 @@ -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) diff --git a/auditlog/readme/CONFIGURE.rst b/auditlog/readme/CONFIGURE.rst index b23252fa80d..1ac23d07061 100644 --- a/auditlog/readme/CONFIGURE.rst +++ b/auditlog/readme/CONFIGURE.rst @@ -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.