Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2a031df
Quick draft of auto-cleaning functionality
Archmonger Jan 31, 2024
f8b99fc
remove auto_clean from config name
Archmonger Feb 1, 2024
685db22
Add type hinting to _cached_static_contents function
Archmonger Feb 1, 2024
eba80d3
ignore_config
Archmonger Feb 1, 2024
2e089de
docs cleanup
Archmonger Feb 1, 2024
4ea41f5
CLEAN_NEEDED_BY caching
Archmonger Feb 1, 2024
836d719
fix link
Archmonger Feb 1, 2024
dbf7e12
fix tests
Archmonger Feb 1, 2024
e1bd185
minor docs wordsmithing
Archmonger Feb 1, 2024
e2c088f
Merge remote-tracking branch 'upstream/main' into robust-cleanup-config
Archmonger Feb 1, 2024
43685b8
Add management command
Archmonger Feb 1, 2024
6c1ecf0
add changelog entries
Archmonger Feb 1, 2024
ef90460
Add checks for new config values
Archmonger Feb 1, 2024
5a57807
better interface for management command
Archmonger Feb 1, 2024
75670a8
ignore settings.py attributes for management command calls
Archmonger Feb 2, 2024
3594cee
add a check for common misspelling
Archmonger Feb 2, 2024
da855dd
Add comment for a bugfix
Archmonger Feb 2, 2024
107b64c
Auto-Clean Settings docs
Archmonger Feb 2, 2024
c6b8e13
fix a few stale docs lines
Archmonger Feb 2, 2024
43ee1ac
remove dead LOC
Archmonger Feb 2, 2024
2799ed0
Django Query Postprocessor docs cleanup
Archmonger Feb 2, 2024
e8fe1da
allow REACTPY_CLEAN_INTERVAL to be None
Archmonger Feb 2, 2024
08e1025
prepare for management command docs
Archmonger Feb 3, 2024
32ceea6
management command docs
Archmonger Feb 3, 2024
3385887
minor docs styling change
Archmonger Feb 3, 2024
e0c771d
avoid django timezone module
Archmonger Feb 3, 2024
05554dc
fix tests
Archmonger Feb 3, 2024
ad62a68
fix tests in a different way
Archmonger Feb 3, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
avoid django timezone module
  • Loading branch information
Archmonger committed Feb 3, 2024
commit e0c771d73af69f71611f524865b39a9809a9e7d5
15 changes: 7 additions & 8 deletions src/reactpy_django/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import TYPE_CHECKING, Literal

from django.contrib.auth import get_user_model
from django.utils import timezone

_logger = logging.getLogger(__name__)

Expand All @@ -28,7 +27,7 @@ def clean(

config = Config.load()
if immediate or is_clean_needed(config):
config.cleaned_at = timezone.now()
config.cleaned_at = datetime.now()
config.save()
sessions = REACTPY_CLEAN_SESSIONS
user_data = REACTPY_CLEAN_USER_DATA
Expand All @@ -53,8 +52,8 @@ def clean_sessions(verbosity: int = 1):
if verbosity >= 2:
print("Cleaning ReactPy component sessions...")

start_time = timezone.now()
expiration_date = timezone.now() - timedelta(seconds=REACTPY_SESSION_MAX_AGE)
start_time = datetime.now()
expiration_date = datetime.now() - timedelta(seconds=REACTPY_SESSION_MAX_AGE)
session_objects = ComponentSession.objects.filter(
last_accessed__lte=expiration_date
)
Expand Down Expand Up @@ -82,7 +81,7 @@ def clean_user_data(verbosity: int = 1):
if verbosity >= 2:
print("Cleaning ReactPy user data...")

start_time = timezone.now()
start_time = datetime.now()
user_model = get_user_model()
all_users = user_model.objects.all()
all_user_pks = all_users.values_list(user_model._meta.pk.name, flat=True) # type: ignore
Expand Down Expand Up @@ -115,15 +114,15 @@ def is_clean_needed(config: Config | None = None) -> bool:
if REACTPY_CLEAN_INTERVAL is None:
return False

if timezone.now() >= CLEAN_NEEDED_BY:
if datetime.now() >= CLEAN_NEEDED_BY:
config = config or Config.load()
CLEAN_NEEDED_BY = config.cleaned_at + timedelta(seconds=REACTPY_CLEAN_INTERVAL)

return timezone.now() >= CLEAN_NEEDED_BY
return datetime.now() >= CLEAN_NEEDED_BY


def inspect_clean_duration(start_time: datetime, task_name: str, verbosity: int):
clean_duration = timezone.now() - start_time
clean_duration = datetime.now() - start_time

if verbosity >= 3:
print(
Expand Down