My app lets people connect their Garmin, Apple Watch, etc, to track activities, join virtual races, and create adventure activity plans. I have a leaderboard which is backed by a LiveView, in turn subscribed to a pub sub channel.
I’m using |> stream
to add leaderboard data into my LiveView. When a new activity comes in from the provider, I broadcast a message with the new aggregate data for that runner.
And like magic, my leaderboard LiveView updates. There’s just one problem. Sorting!
If a runner overtakes another, the leaderboard is out of order. One simple fix is just to recompute the whole thing. But that feels inefficient — I can’t rely on stream_insert
anymore.
Yet sorting at the template level also seems like it violates the design intention of streams.
Any thoughts on the “right” way to resolve this? Thank you!