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

Store server data for multiple accounts at once #5005

Open
gnprice opened this issue Sep 16, 2021 · 0 comments
Open

Store server data for multiple accounts at once #5005

gnprice opened this issue Sep 16, 2021 · 0 comments
Labels
a-data-sync Zulip's event system, event queues, staleness/liveness a-multi-org a-redux blocked on other work To come back to after another related PR, or some other task. P1 high-priority

Comments

@gnprice
Copy link
Member

gnprice commented Sep 16, 2021

Currently we store almost all data from the server -- things like what other users exist, what streams, what messages, and how many unreads you have -- for just one account at a time, the "active account" (see our glossary). When you switch to look at another account, that one becomes the active account, and we discard the data from the previously active account.

Instead, we should maintain all this data for all the user's accounts, all the accounts they're logged into.

This is a prerequisite for many of our issues in the "multi-org" area. In particular it's necessary for:

and helpful or likely-necessary for:

We don't have to do this all at once. We can have intermediate states where some parts of the server data are kept only for the active account, and others are kept for all accounts.

In fact the status quo is such an intermediate state: we keep a handful of small pieces of server data in state.accounts, which is the one place that currently keeps data for all accounts. These include the Zulip server version and feature level, and the user's user ID.

Prerequisites for fully doing this include:

@gnprice gnprice added a-multi-org a-redux a-data-sync Zulip's event system, event queues, staleness/liveness P1 high-priority blocked on other work To come back to after another related PR, or some other task. labels Sep 16, 2021
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Dec 8, 2021
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.

Also expand a few comments and clarify that they only apply in the
pre-zulip#5005 world, and add TODOs to remove them when we complete zulip#5005
so we don't forget.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 8, 2022
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.

Also expand a few comments and clarify that they only apply in the
pre-zulip#5005 world, and add TODOs to remove them when we complete zulip#5005
so we don't forget.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 9, 2022
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.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 12, 2022
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.
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this issue Mar 12, 2022
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.
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this issue Dec 13, 2022
Most of these state subtrees hold per-account data we get from the
server. In the current pre-zulip#5005 design, where we only store server
data for one account, these should already have been clearing out on
LOGIN_SUCCESS, like we do with messages, narrows, etc.

Two of the subtrees, `outbox` and `drafts`, hold client-side
per-account data. Just as with server data, we've only been keeping
these around for the active account, and like the other reducers
touched in this commit, we've forgotten to handle LOGIN_SUCCESS for
them. So, do that.

Now, all the server-data subtrees and `outbox` and `drafts` all
reset on ACCOUNT_SWITCH, LOGIN_SUCCESS, and LOGOUT. That's part of
Greg's proposed fix for zulip#4446.

Next, we'll do the next part:

> * I think it'd be a useful refactor to consolidate one action type
>   like `CLEAR_ACCOUNT_DATA`.
>   * The action creators for these three (in `accountActions.js`) can
>     dispatch that first, then also a `LOGOUT` etc.
>   * Almost all the reducers would respond only to the
>     `CLEAR_ACCOUNT_DATA`.
>   * There are a couple of exceptions, like `accountReducers` and
>     `sessionReducers`, that actually want to treat the three cases
>     differently. Those would be the only ones to continue responding
>     to `LOGOUT` etc.; and they'd stand out better as a result.
>   * Then there are further changes we might make to those, but
>     that'll be easier to see after that.

Fixes-partly: zulip#4446
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-data-sync Zulip's event system, event queues, staleness/liveness a-multi-org a-redux blocked on other work To come back to after another related PR, or some other task. P1 high-priority
Projects
None yet
Development

No branches or pull requests

1 participant