-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
|
||
from .models import TimelineLog | ||
|
||
|
||
def prune_timeline_logs(*, keep_days: int | None = None) -> int: | ||
"""Delete the timeline logs instances. | ||
:param keep_days: If specified, only delete records older than the specified number of days. | ||
:returns: The number of deleted instances. | ||
""" | ||
limit = timezone.now() | ||
if keep_days is not None: | ||
limit -= timedelta(days=keep_days) | ||
|
||
number, _ = TimelineLog.objects.filter(timestamp__lte=limit).delete() | ||
return number |