Skip to content
Open
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
22 changes: 13 additions & 9 deletions litellm/proxy/auth/auth_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,17 +709,21 @@ def _should_check_db(
"""
Prevent calling db repeatedly for items that don't exist in the db.
"""
current_time = time.time()
# if key doesn't exist in last_db_access_time -> check db
if key not in last_db_access_time:
# Avoid multiple lookups and tuple unpacking by minimizing dictionary accesses
try:
value = last_db_access_time[key]
except KeyError:
return True
elif (
last_db_access_time[key][0] is not None
): # check db for non-null values (for refresh operations)

v0 = value[0]
if v0 is not None:
return True

# Only call time.time() if needed
# value is assumed to be [None, <timestamp>] or similar
current_time = time.time()
if current_time - value >= db_cache_expiry:
return True
elif last_db_access_time[key][0] is None:
if current_time - last_db_access_time[key] >= db_cache_expiry:
return True
return False


Expand Down