Skip to content
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

Closed

Conversation

sweep-ai[bot]
Copy link
Contributor

@sweep-ai sweep-ai bot commented May 11, 2024

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

  • Added a dependency injection for RedisCacheManager in backend/dependencies/auth.py to enable caching within the authentication process.
  • Modified the get_current_user function to:
    • Check if the user's information is available in the Redis cache before attempting to authenticate through our primary authentication service.
    • Cache authenticated user data in Redis with a 5-minute expiration if it's not already cached.
  • This implementation leverages the existing AuthService for user authentication and introduces interactions with Redis through the RedisCacheManager for caching purposes.
  • Affected files and directories:
    • Modified backend/dependencies/auth.py to include changes in the authentication process.
    • Dependencies on RedisCacheManager and get_redis_cache_manager have been added to support caching.

Fixes #66.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To get Sweep to edit this pull request, you can:

  • Comment below, and Sweep can edit the entire PR
  • Comment on a file, Sweep will only modify the commented file
  • Edit the original issue to get Sweep to recreate the PR from scratch

This is an automated message generated by Sweep AI.

Copy link
Contributor Author

sweep-ai bot commented May 11, 2024

Rollback Files For Sweep

  • Rollback changes to backend/dependencies/auth.py

This is an automated message generated by Sweep AI.

Comment on lines +24 to +37
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
Copy link
Collaborator

@bonk1t bonk1t May 11, 2024

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

Copy link
Contributor Author

@sweep-ai sweep-ai bot May 11, 2024

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.

@AI-in-Hand AI-in-Hand deleted a comment from sweep-ai bot May 11, 2024
@bonk1t
Copy link
Collaborator

bonk1t commented May 12, 2024

in
backend/dependencies/auth.py:
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

Copy link
Contributor Author

sweep-ai bot commented May 12, 2024

❌ 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.

@bonk1t bonk1t closed this May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement get_current_user caching in Redis with 5 min expiration
1 participant