diff --git a/judge/user_log.py b/judge/user_log.py index b8aec43..ab4ee53 100644 --- a/judge/user_log.py +++ b/judge/user_log.py @@ -1,5 +1,6 @@ from django.utils.timezone import now from django.conf import settings +from django.core.cache import cache from judge.models import Profile @@ -15,11 +16,14 @@ class LogUserAccessMiddleware(object): hasattr(request, "user") and request.user.is_authenticated and not getattr(request, "no_profile_update", False) + and not cache.get(f"user_log_update_{request.user.id}") ): updates = {"last_access": now()} # Decided on using REMOTE_ADDR as nginx will translate it to the external IP that hits it. if request.META.get(settings.META_REMOTE_ADDRESS_KEY): updates["ip"] = request.META.get(settings.META_REMOTE_ADDRESS_KEY) Profile.objects.filter(user_id=request.user.pk).update(**updates) + cache.set(f"user_log_update_{request.user.id}", True, 120) + print("UPDATE", updates) return response