-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Presence onJoin callback includes old metas in newPresence var #3475
Comments
Also, onJoin and onLeave both call a function with 3 arguments: key, currentPresence, newPresence OR leftPresence. The currentPresence however seems to be different for both of them: onJoin currentPresence value is the same value as before the update. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. I'm ok submitting a PR but I'm not really sure what is the correct behavior here. |
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this also helped to get rid of the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this also helped to get rid of the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this also helped to get rid of the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this also helped to get rid of the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this also helped to get rid of the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this also helped to get rid of the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Syncing presences was very slow due to using clone(). For channels that have couple of thousand of users where users are joining/leaving and we also have updates, clone() used almost all the CPU. onJoin and onLeave callbacks were merged into one onChange callback. This is because previous onJoin and onLeave callbacks were very confusing and this way we don't have to use the the clone function. Previously onJoin and onLeave both were called with 3 arguments: key, currentPresence and newPresence/leftPresence. The currentPresence however was the same value as before the update for onJoin, but updated presence (joins/leaves processed) for onLeave. So in onJoin case we get the state before the changes and in onLeave case we get the state after all the changes. Also the old onJoin newPresence variables included metas that were in leaves payload which made it hard to detect a join vs an update. New onChange callback includes the previous presence (state before the updates) and new presence (state after the updates) which makes it much easier to process changes and see what has happened. onJoin and onLeave are still in the API because of backwards compatibility but they're marked as deprecated. This addresses both phoenixframework#3509 and phoenixframework#3475
Environment
Issue
Given: I have a user with one tab (one meta)
When: I update the user (from phoenix presence in elixir)
Then: I expect
newPresence
to include one meta with the updated dataACTUAL:
newPresence
has two metas, one old and one updatedIf I force onJoin to next event loop like this:
then
newPresence
includes only one meta which is the updated meta, which I actually expect.Digging in the code
As I understand then here https://github.com/phoenixframework/phoenix/blob/master/assets/js/phoenix.js#L1329
state[key]
is set tonewPresence
. Thenstate[key].metas.unshift(...curMetas)
adds current metas to the state[key]. This however also mutates thenewPresence
because the var was not cloned. ThenonJoin(key, currentPresence, newPresence)
is called wherenewPresence
now has the old metas as well.setTimeout works because this forces https://github.com/phoenixframework/phoenix/blob/master/assets/js/phoenix.js#L1337 to iterate over leaves which mutates newPresence to be correct again.
It seems to be that this is not a correct behavior. If it is, can you explain why?
The issue does not exist with
onSync
callback because that's called after both joins and leaves are processed. We however don't want to useonSync
because we want unchanged presences to remain referentially equivalent whichonSync
does not provide as it clones the entire list. Our online user list has thousands of users and we want to leverage referential equivalence and also don't want to map over the whole list each time for fast react based dom updates.The text was updated successfully, but these errors were encountered: