-
-
Notifications
You must be signed in to change notification settings - Fork 672
Stop event-polling for an account when it's logged out #5161
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,15 @@ import { getHasAuth } from '../account/accountsSelectors'; | |
| * See {@link SessionState} for discussion of what "non-persistent" means. | ||
| */ | ||
| export type PerAccountSessionState = $ReadOnly<{ | ||
| /** | ||
| * The event queue ID that we're currently polling on, if any. | ||
| * | ||
| * Null when we're not polling on any event queue: | ||
| * - Between startup and registering a queue | ||
| * - After the server tells us our old queue was invalid, and before we've | ||
| * registered a new one | ||
| * - While this account is logged out | ||
| */ | ||
| eventQueueId: string | null, | ||
|
|
||
| /** | ||
|
|
@@ -162,26 +171,43 @@ export default (state: SessionState = initialState, action: Action): SessionStat | |
| ...state, | ||
| needsInitialFetch: true, | ||
| loading: false, | ||
|
|
||
| // The server told us that the old queue ID is invalid. Forget it, | ||
| // so we don't try to use it. | ||
| eventQueueId: null, | ||
|
Comment on lines
+174
to
+177
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, good idea. We should probably do the same thing when the active account changes, too, right? That is, on LOGOUT, LOGIN_SUCCESS, and ACCOUNT_SWITCH. (More precisely when the logged-in active account changes: the latter two are the two ways the active account changes, and the former causes the active account to no longer be logged-in.) Those are the actions that clear most of the rest of the state. |
||
| }; | ||
|
|
||
| case LOGIN_SUCCESS: | ||
| return { | ||
| ...state, | ||
| needsInitialFetch: true, | ||
|
|
||
| // We're about to request a new event queue; no use hanging on to | ||
| // any old one we might have. | ||
| eventQueueId: null, | ||
| }; | ||
|
|
||
| case LOGOUT: | ||
| return { | ||
| ...state, | ||
| needsInitialFetch: false, | ||
| loading: false, | ||
|
|
||
| // Stop polling this event queue. | ||
| eventQueueId: null, | ||
| }; | ||
|
|
||
| case ACCOUNT_SWITCH: | ||
| return { | ||
| ...state, | ||
| needsInitialFetch: true, | ||
| loading: false, | ||
|
|
||
| // Stop polling this event queue. (We'll request a new one soon, | ||
| // for the new account.) | ||
| // TODO(#5005): Keep polling on accounts other than the active | ||
| // account. | ||
| eventQueueId: null, | ||
| }; | ||
|
|
||
| case REHYDRATE: | ||
|
|
||
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.
I like this summary line! This seems like a good basis for thinking about what the behavior should be.
Uh oh!
There was an error while loading. Please reload this page.
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.
Cool!
It has one inaccuracy, possibly not worth mentioning: this could be
nullwhile we still have a poll request in progress, since we don't cancel in-progress fetches yet.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.
Yeah. Given that in that situation when the request eventually finishes, we're going to throw away the result without doing anything with it, I think it's still fair to say that we're not "currently polling on" that queue -- we do still have an HTTP request open, but as far as the app's logical behavior is concerned it already may as well not exist.