-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add site channels for realtime #40720
Conversation
Works great! I see comments appear on both sides :) what can I do to debug this better? After submitting a comment Reader side I see it double for a couple of seconds. |
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Webpack Runtime (~218 bytes removed 📉 [gzipped])
Webpack runtime for loading modules. It is included in the HTML page as an inline script. Is downloaded and parsed every time the app is loaded. App Entrypoints (~12608 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~92183 bytes removed 📉 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~43246 bytes removed 📉 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
This should be ready for review, unit tests on the way 😟
|
c61a6d3
to
3951dc2
Compare
Good point, forgot to add it back.
I'm not quite sure where that code was, refreshing the stream will have some attempts because of the flickering of the visible posts on reload but a channel should be actually joined once.
Added.
Updated. |
I'm still looking into some performance issues around requesting comments which breaks my |
Managed to reproduce, fixed it. |
Should be ready for another round, will investigate the performance issues in another PR. |
* Adjust user and public post channels * Going for it * Buzzsaw * Imports * Temp * Partial * Remove direct phoenix dependency * Bump client * Relive user channel * A working socket manager... should move more to the Lasagna client probably * Pivot toward #40720 Props Andrei. * Smaller * Bump lasagna.js version * Enliven the private content JWTs * Param rename * Add user channel content type param * Bump lasagna.js version again * Transpile See Team Calypso in Slack at this time. * Do it right though
Closed in favor of using lasagna.js |
Changes proposed in this Pull Request
The goal is to have real time comments appear in all Reader sections while keeping the number of joined channels per socket to a minimum. We are using one lasagna channel per site instead of having a channel for each post, that should help us reduce the number of joined channels and join/leave actions.
Concepts
Lasagna is built using Phoenix which gives us multiplexing capabilities allowing one socket connection to handle multiple concerns. At the moment we are having two types of channels (concerns) that are handled via the same websocket.
Sockets
At the moment we are connecting to the Lasagna socket only inside Reader, which means whenever a user navigates to the Reader (or one of its subsections) a socket is opened. Leaving the reader will close that socket. This happens in the lasagna middleware and it will make sure we only have one socket open at a time.
Lifecycle
We keep track of the socket connection status with the following states
init
socket was code was initiliazedopening
socket is in the process of connectingopen_error
there was an error during connection stepopened
socket is opened for communicationclosed
socket is closed for communicationChannels
There are currently two different channel types (topics) that are supported for realtime communication.
User Channels
User specific channel using a topic like
user:wpcom:<userId>
it will be joined when the socket is connected and will be left on socket disconnect. At this point this is channel is not used but it could be easily handling any realtime user specific concerns.Site Channels
Site specific channel using a topic like
public:push:site:<siteId>
, it is used to transmit per site updates. A user can join multiple site channels depending on how many sites are of interested. Currently these are used only in the Reader section, to update comments in realtime.These are rules for when a user can join or leave a site channel:
We have a special management for these channels to make sure we don't have too many "opened" (joined) at the same time.
Feed full post view
Whenever the user clicks on a post from Following Sites it will be sent to a full post view for that feed item (url like
/read/feeds/<feedId>/posts/<itemId>
) at this point if the socket it is not connected we will attempt that and then join the site channel of this particular post.Site full post view
Whenever the user clicks on a post from Conversations it will be sent to a full post view for that blog item (url like
/read/blog/<blogId>/posts/<postId>
) at this point if the socket it is not connected we will attempt that and then join the blog channel of this particular post.Conversation
For the Conversations sections we will connect to the socket as soon as possible and join the channels for the visible site posts, while scrolling we will detect visible site posts and join their channel. We keep the currently viewed site and post ids in
redux/reader/viewing
.To do
New Posts
sticker which on click would populate the feed with a new duplicated post containing new commentsTesting instructions
wp-content/mu-plugins/lasagna.php
tonpm install
Edge cases
In development we expose
window.SOCKET
andwindow.CHANNELS
to help us see what is the current state of our socket and joined channels.We also have lots of debug logs that can be followed to make sure channel management works correctly, you can enable those by running
localStorage.debug = "lasagna:*"
in the browser console.Site channel conditions for join/leave should be tested carefully, we could update the constants for easier testability, decreasing the number of max channel or the lifetime of a channel.
Feed Full Post
Feed Site Post
Conversations
When first joining this there is a blip when more posts are visible until all comments load, that is why there is a lot of attempts to join/leave in the console on hard refresh.