Skip to content

Commit

Permalink
feat: allow clearing view logs
Browse files Browse the repository at this point in the history
These dont need to exist for eternity. Let site admins decide when to
drop them.
  • Loading branch information
ankush committed Jun 2, 2023
1 parent f127734 commit cb885a8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion frappe/core/doctype/view_log/view_log.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Copyright (c) 2018, Frappe Technologies and contributors
# License: MIT. See LICENSE

import frappe
from frappe.model.document import Document


class ViewLog(Document):
pass
@staticmethod
def clear_old_logs(days=180):
from frappe.query_builder import Interval
from frappe.query_builder.functions import Now

table = frappe.qb.DocType("View Log")
frappe.db.delete(table, filters=(table.modified < (Now() - Interval(days=days))))

2 comments on commit cb885a8

@gavindsouza
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code block really required? Feels like something that should be configurable from the Desk 🤔

@ankush
Copy link
Member Author

@ankush ankush commented on cb885a8 Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept the actual deletion in code because not every doctype "just" deletes old logs.

  • Email queue deletes child table
  • prepared reports need to delete files too
  • some other doctype which I can't recall only deleted rows with particular status

Please sign in to comment.