Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
source-root: .
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
Expand Down
133 changes: 28 additions & 105 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ django-redis = "^5.4.0"
redis = "^6.4.0"
mysqlclient = "^2.2.4"
psutil = "^7.1.3"
defusedxml = "^0.7.1"

[tool.poetry.group.dev.dependencies]
djlint = "^1.34.1"
Expand Down
24 changes: 24 additions & 0 deletions web/management/commands/cleanup_expired_messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from typing import Any

from django.core.management.base import BaseCommand

from web.models import PeerMessage
from web.secure_messaging import MESSAGE_RETENTION_DAYS, get_message_retention_cutoff


class Command(BaseCommand):
"""Management command to delete peer messages older than the retention period."""

help = f"Deletes direct messages older than {MESSAGE_RETENTION_DAYS} days."

def handle(self, *args: Any, **options: Any) -> None:
"""
Execute the management command to remove expired messages.

Deletes all PeerMessage records created before the retention cutoff
and reports the count of deleted messages to stdout.
"""
cutoff = get_message_retention_cutoff()
expired_qs = PeerMessage.objects.filter(created_at__lt=cutoff)
deleted_count, _ = expired_qs.delete()
self.stdout.write(self.style.SUCCESS(f"Successfully deleted {deleted_count} expired messages"))
5 changes: 5 additions & 0 deletions web/management/commands/run_daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def handle(self, *args, **options):
call_command("cleanup_abandoned_drafts")
self.stdout.write(self.style.SUCCESS("Successfully completed cleanup_abandoned_drafts"))

# Clean up expired direct messages
self.stdout.write("Running cleanup_expired_messages...")
call_command("cleanup_expired_messages")
self.stdout.write(self.style.SUCCESS("Successfully completed cleanup_expired_messages"))

except Exception as e:
self.stdout.write(self.style.ERROR(f"Error running daily tasks: {str(e)}"))
raise e
Expand Down
Loading
Loading