-
Notifications
You must be signed in to change notification settings - Fork 47
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
Optimize session verification strategy in AtlasProvider #1717
Comments
Token expiration time should be used instead. Any |
Could this approach help? Ive made it with assistance of GeminiAI Understanding the Current Approach: The current implementation uses setInterval to verify the session every 5 seconds. This might be unnecessary frequent and impact performance, especially for long-running sessions. Proposed Dynamic Approach: A dynamic approach could be more efficient. Here's a potential strategy: Calculate a Base Verification Interval: Determine a reasonable base interval for session verification (e.g., 30 seconds). This interval will be used as a starting point for verification. Adjust Interval Based on Session Duration: As the session progresses, gradually increase the verification interval. This could be done using a logarithmic or exponential function to avoid excessive verification for long sessions. For instance, you could multiply the base interval by a factor of 1.5 every 5 minutes. Consider User Activity: If the user is actively interacting with the application (e.g., clicking buttons, typing), you could reset the verification interval to the base value or a shorter duration. This ensures that the session is verified more frequently during active user interactions. Implementation Example: ˋˋˋJavaScript import React, { useEffect, useState } from 'react'; const AtlasProvider = () => { const [verificationInterval, setVerificationInterval] = useState(30 * 1000); // 30 seconds const [sessionStartTime, setSessionStartTime] = useState(Date.now()); useEffect(() => { const intervalId = setInterval(() => { // Verify session here // ... // Adjust verification interval based on session duration const elapsedTime = Date.now() - sessionStartTime; const newInterval = verificationInterval * (1 + Math.log(elapsedTime / 60000)); // Adjust the formula as needed setVerificationInterval(newInterval); }, verificationInterval); return () => clearInterval(intervalId); }, [verificationInterval, sessionStartTime]); return ( // ... ); }; ˋˋˋ Key Points: Experiment with different formulas and factors to find the optimal balance between performance and security. Consider additional factors like user role or ¿application sensitivity? when determining the verification interval. Test the optimized implementation thoroughly to ensure it doesn't introduce any unintended side effects. By adopting a dynamic approach, you could significantly reduce unnecessary session verifications and improve the overall performance of your application. |
@MAMware The expiration time is already contained in the token, there should be no need to do polling to validate it. If something very unexpected happen (for example large time offset between client and server making the client consider the token valid while it is not), we should rely on 401 to detect authentication issues and request a new token. We are not using sessions (kept server side, potentially adjustable) but tokens with fixed values. Ideally, we should be using a pair of tokens (auth/refresh), but we have only auth at the moment. |
As discussed in PR #1654, there's an opportunity to optimize the session verification strategy in
AtlasProvider.tsx
. The current implementation verifies the session every 5 seconds usingsetInterval
, which may be unnecessarily frequent and impact performance.PR: #1654
Comment: #1654 (comment)
Requester: @jaybuidl
The text was updated successfully, but these errors were encountered: