You can def solve it the way you done already. An alternative is to make a sticky liveview of the sidebar.
The benefits with that would be that you don’t need to fetch the data from the db every time you mount a new liveview (if you for example navigate across liveview sessions) and that you only need to subscribe to the topic in one liveview (the sidebar-liveview). Downside is that it can be a bit overkill (I don’t have a benchmark but I guess having sticky LiveViews have a server cost) and make things more complex (for example if you wanna show the current page option you might have to write some extra js to update that).
Good overview of it: Keep LiveViews alive across live redirects · The Phoenix Files
I would probably stick to your solution if it is only number_of_users in database that needs to be tracked in the sidebar. Sticky liveview is more “worth” it if you for example track 5 different stuff (for example notifications, new messages, new friend requests, etc) in my opinion.






















