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

[16.0][FIX] auditlog: Allow passing a chunk size for autovacuum #2528

Merged
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
4 changes: 4 additions & 0 deletions auditlog/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
4 changes: 4 additions & 0 deletions auditlog/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion auditlog/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Audit Log</title>
<style type="text/css">

Expand Down Expand Up @@ -401,6 +401,9 @@ <h1><a class="toc-backref" href="#id1">Usage</a></h1>
<cite>Configuration / Technical / Automation / Scheduled Actions</cite> menu and edit the
<cite>Auto-vacuum audit logs</cite> entry:</p>
<img alt="https://raw.githubusercontent.com/OCA/server-tools/16.0/auditlog/static/description/autovacuum.png" src="https://raw.githubusercontent.com/OCA/server-tools/16.0/auditlog/static/description/autovacuum.png" />
<p>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.</p>
<p>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 <cite>View Logs</cite> action. The second group is the
Expand Down