Improve event live listing #185
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When listing and paginating events in the event live views, we sometimes get a duplicate IDs error like this:
This could happen in several ways, but one of them that I could reproduce easily is by listing events on a tab, then creating an event on a new tab, then loading the second page of events on the first tab:
duplicate-event-id.mp4
This happens because the original view becomes stale and because we use offset-limit pagination, the second page loads an event that was already on the stale version of the first page. A duplicate ID runtime exception is triggered in this case, but the app would also currently silently fail by missing one event on "load more" if an event was deleted from the top of the list (on a different tab). Similar scenarios could happen when an event is terminated, for example, because the event moves from one list to another.
Solutions
There's a few things that we could improve in general with this part of the app:
PubSubmessages to avoid having stale views.This PR currently expands and lightly refactors the user events
PubSubsubscription and broadcasting, refreshing the list of events. This prevents the duplicate ID problem but also makes the UI more responsive to changes.@alxlion, happy to change the approach or rewrite the PR, let me know what you think. There's many other things that I'm tempted to suggest we change, but I'm trying to keep refactors to a sensible minimum.
Testing
Aside from running
mix test, I manually opened up a couple of tabs for two different users and I tested creating, updating and deleting events to make sure that views would refresh correctly.