Resources subscribed over websocket never unsubscribed [Optimization]
Opened this issue · 1 comments
adileo commented
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 ifcallbackArray
is empty then trigger astore.unSubscribeWebSocket
Any side issues that could arise from this?
joepio commented
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.