Skip to content

Commit

Permalink
Merge PR #2591 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by hbrunn
  • Loading branch information
OCA-git-bot committed Apr 18, 2023
2 parents 46b5a4b + 701963a commit f5f4085
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions auditlog/models/autovacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
22 changes: 22 additions & 0 deletions auditlog/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Rules
~~~~~

Go to `Settings / Technical / Audit / Rules` to subscribe rules. A rule defines
which operations to log for a given data model.

.. image:: ../static/description/rule.png

Cleanup
~~~~~~~

A scheduled action exists to delete logs older than 6 months (180 days)
automatically but is not enabled by default.
To activate it and/or change the delay, go to the
`Configuration / Technical / Automation / Scheduled Actions` menu and edit 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 f5f4085

Please sign in to comment.