diff --git a/auditlog/README.rst b/auditlog/README.rst index e860ba11197..66125fa9870 100644 --- a/auditlog/README.rst +++ b/auditlog/README.rst @@ -58,6 +58,10 @@ To activate it and/or change the delay, go to the .. image:: https://raw.githubusercontent.com/OCA/server-tools/16.0/auditlog/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. + There are two possible groups configured to which one may belong. The first is the Auditlog User group. This group has read-only access to the auditlogs of individual records through the `View Logs` action. The second group is the diff --git a/auditlog/models/autovacuum.py b/auditlog/models/autovacuum.py index 4803a1d6eb2..bf56fc52961 100644 --- a/auditlog/models/autovacuum.py +++ b/auditlog/models/autovacuum.py @@ -13,7 +13,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 @@ -26,9 +26,12 @@ def autovacuum(self, days): data_models = ("auditlog.log", "auditlog.http.request", "auditlog.http.session") 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) return True diff --git a/auditlog/readme/USAGE.rst b/auditlog/readme/USAGE.rst index 05c61d88200..12bf66c12a0 100644 --- a/auditlog/readme/USAGE.rst +++ b/auditlog/readme/USAGE.rst @@ -20,6 +20,10 @@ To activate it and/or change the delay, go to the .. 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. + There are two possible groups configured to which one may belong. The first is the Auditlog User group. This group has read-only access to the auditlogs of individual records through the `View Logs` action. The second group is the diff --git a/auditlog/static/description/index.html b/auditlog/static/description/index.html index 0b44b0115b5..029f935f008 100644 --- a/auditlog/static/description/index.html +++ b/auditlog/static/description/index.html @@ -3,7 +3,7 @@
- +