-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sweep: Implement get_current_user caching in Redis with 5 min expiration #107
Conversation
Rollback Files For Sweep
This is an automated message generated by Sweep AI. |
user_id = auth_service.get_user_id_from_token(token) | ||
|
||
# Check if the user is in the Redis cache | ||
cached_user = await redis_cache_manager.get(user_id) | ||
if cached_user: | ||
return User(**cached_user) | ||
|
||
# If not in cache, authenticate with Firebase | ||
user = auth_service.get_user(token) | ||
|
||
# Store the authenticated user in the Redis cache with a 5 minute expiration | ||
await redis_cache_manager.set(user_id, user.dict(), ex=300) | ||
|
||
return user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use token as key. Don't extract user_id from token. Use user.model_dump()
to convert user
into dictionary.
Also, update the tests in tests/unit/dependencies/test_auth.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Failed to make changes:
The exception message is:not enough values to unpack (expected 4, got 3)
The stack trace is:Traceback (most recent call last):
File "/app/sweepai/handlers/on_comment.py", line 370, in on_comment
modify_files_dict, changes_made, _, file_change_requests = handle_file_change_requests(
ValueError: not enough values to unpack (expected 4, got 3)
Please join our Discourse to report this issue.
This is an automated message generated by Sweep AI.
in |
❌ Failed to make changes: The exception message is:not enough values to unpack (expected 4, got 3) The stack trace is:Traceback (most recent call last): Please join our Discourse to report this issue. This is an automated message generated by Sweep AI. |
Description
This pull request introduces caching for authenticated users in Redis, aiming to reduce the load on our authentication service by caching user data for 5 minutes. This change is expected to improve the performance of our system by decreasing the number of direct authentication requests needed for users who are actively interacting with our application.
Summary
RedisCacheManager
inbackend/dependencies/auth.py
to enable caching within the authentication process.get_current_user
function to:AuthService
for user authentication and introduces interactions with Redis through theRedisCacheManager
for caching purposes.backend/dependencies/auth.py
to include changes in the authentication process.RedisCacheManager
andget_redis_cache_manager
have been added to support caching.Fixes #66.
🎉 Latest improvements to Sweep:
💡 To get Sweep to edit this pull request, you can:
This is an automated message generated by Sweep AI.