Преглед изворни кода

Only update every 60 seconds

Pieter Lambrecht пре 3 година
родитељ
комит
5d4575ed25
1 измењених фајлова са 5 додато и 3 уклоњено
  1. 5 3
      netbox/netbox/api/authentication.py

+ 5 - 3
netbox/netbox/api/authentication.py

@@ -19,9 +19,11 @@ class TokenAuthentication(authentication.TokenAuthentication):
         except model.DoesNotExist:
         except model.DoesNotExist:
             raise exceptions.AuthenticationFailed("Invalid token")
             raise exceptions.AuthenticationFailed("Invalid token")
 
 
-        # Update last used.
-        token.last_used = timezone.now()
-        token.save()
+        # Update last used, but only once a minute. This reduces the write load on the db
+        timediff = timezone.now() - token.last_used
+        if timediff.total_seconds() > 60:
+            token.last_used = timezone.now()
+            token.save()
 
 
         # Enforce the Token's expiration time, if one has been set.
         # Enforce the Token's expiration time, if one has been set.
         if token.is_expired:
         if token.is_expired: