-
-
Notifications
You must be signed in to change notification settings - Fork 679
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
Conversation
3563894 to
227b92f
Compare
|
I've just rebased this past #5259. I'd appreciate a review! 🙂 |
gnprice
left a comment
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.
Thanks! Comments below.
src/events/eventActions.js
Outdated
| if (queueId !== getState().session.eventQueueId) { | ||
| // The user switched accounts or logged out. | ||
| // TODO(#5022): TODO(#5009): This doesn't seem like an adequate | ||
| // check for that; it looks like it only detects a new REGISTER_COMPLETE. | ||
| // Pre-#5005, this will catch that the user has switched accounts, | ||
| // as long as the old and new accounts' queue IDs don't collide. |
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.
Just after a conditional (at the start of the body), I like to have a short comment that states the fact we've learned is true. That then serves as an anchor for the reader to understand what comes next.
It's OK if there are some other cases where the same fact is true but that don't lead into this code path. That can be an important thing to go on to clarify, but it doesn't make the base comment invalid: if we are in this code path, then the fact is true.
If this condition holds, is the comment "The user switched accounts or logged out." not necessarily true? I feel like I'd have to do some digging to verify that it is true; but I don't see anything in this commit asserting that it isn't, only that it's incomplete.
src/events/eventActions.js
Outdated
| // (again, pre-#5005) is that it's caught before we're set up with | ||
| // a new loop for the new account, so that the old and new account | ||
| // aren't writing to the same piece of state at the same time. | ||
| // TODO(#5005): Remove the "Pre-#5005" comment above. |
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 don't understand this line. Is it saying to delete the entire paragraph above? But then there'd be no comment at all explaining what this condition is about.
(After the second commit, there's a further comment below saying to delete the whole conditional. But after the first commit there isn't; and once there is that further comment, does this line add anything distinct?)
|
|
||
| // The server told us that the old queue ID is invalid. Forget it, | ||
| // so we don't try to use it. | ||
| eventQueueId: null, |
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.
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.
src/chat/ChatScreen.js
Outdated
| // event queue has changed; it can't mean that we had a queue ID and | ||
| // dropped it.) | ||
| React.useEffect(scheduleFetch, [eventQueueId]); | ||
| // When we have a new event queue ID, schedule a fetch. |
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.
nit:
| // When we have a new event queue ID, schedule a fetch. | |
| // When we have a new event queue, schedule a fetch. |
227b92f to
d2d5543
Compare
|
Thanks for the review! Revision pushed. 🙂 |
gnprice
left a comment
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.
Thanks for the revision! Just small comments below.
| */ | ||
| export type PerAccountSessionState = $ReadOnly<{ | ||
| /** | ||
| * The event queue ID that we're currently polling on, if any. |
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.
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 null while 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.
src/session/sessionReducer.js
Outdated
| * - After the server tells us our old queue was invalid, and before we've | ||
| * registered a new one | ||
| * - While this account is logged out | ||
| * - While this account is logged in but is not the active account |
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 don't think this item applies.
- At present, the only per-account state we have is the one for the active account. So "this account" here is always the active account.
- In a future where we have any per-account session state for accounts other than the active account, I think that will go together with maintaining an event queue for those accounts.
src/session/sessionReducer.js
Outdated
| // Although it may be valid, forget the event queue ID -- we know | ||
| // the user won't care about it. |
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'd frame this a bit differently:
| // Although it may be valid, forget the event queue ID -- we know | |
| // the user won't care about it. | |
| // Stop polling this event queue. |
src/session/sessionReducer.js
Outdated
| // Although it may be valid, forget the old account's event queue -- | ||
| // we know the user won't care about it. We also know we're about to | ||
| // request a new event queue; no use hanging on to the old one. |
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.
Similarly:
| // Although it may be valid, forget the old account's event queue -- | |
| // we know the user won't care about it. We also know we're about to | |
| // request a new event queue; no use hanging on to the old one. | |
| // Stop polling this event queue. (We'll request a new one soon, | |
| // for the new account.) |
d2d5543 to
bed5dad
Compare
|
Thanks for the review! Revision pushed. |
In a multi-account, post-zulip#5005 world, we're likely to want a live event queue for all the logged-in accounts. So we'll want this function to start polling for "this account", not for the global "active account". The action is already typed as a `ThunkAction`, not a `GlobalThunkAction`; that's a good start. The `auth` object we're working with after the code change is the same one as before, we just get it more directly. (`tryGetAuth` uses `getAccount`, which, pending zulip#5005, assumes "the account" is the active account; see the implementation comment in `getAccount`.) And, with zulip#5005, it will naturally change to be the Auth object for "this account", the one the caller cares about.
bed5dad to
069c82c
Compare
|
Thanks! Looks good; merging. |
And make a few other cleanups and comments.
Fixes: #5022
Related: #5009