Skip to content
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

Resources subscribed over websocket never unsubscribed [Optimization] #311

Open
adileo opened this issue Mar 4, 2023 · 1 comment
Open

Comments

@adileo
Copy link
Contributor

adileo commented Mar 4, 2023

It looks like that store.unSubscribeWebSocket is never called.

This means that the client once a hook like useResource is used it will keep listening over websocket for updates that no one reads.

Fix proposal:

  • within store.unsubscribe() check if callbackArray is empty then trigger a store.unSubscribeWebSocket

Any side issues that could arise from this?

@joepio
Copy link
Member

joepio commented Mar 4, 2023

Thanks for the suggestion!

Some time ago, this was the actual behavior. However, this had the following issue:

  • View a resource X. The client subscribes to changes for X.
  • Hide resource X (e.g. open resource Y). The websocket now also unsubscribes to updates from X.
  • Have some other client make changes to resource X. These changes are not sent to the client.
  • Open resource X again. Now it will show an outdated version, because it did not see older items. The client does not know it needs to update.

We can deal with this in two ways:

  • Always re-fetch the resource when rendering it in the DOM. This can be very costly, and will result in a lot of requests.
  • Keep subscriptions open for all shown resources (current implementation). This sometimes leads to irrelevant Commits being sent and parsed, but as long as clients once in a while re-load their store (e.g. by refreshing the page) that is a small price to pay.

So unfortunately, I think it's better to keep things the way they are now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants