fix(database): retrieve initial list content once - #820
Conversation
|
Your approach is much simpler! Do know though, that the data is still only retrieved once over the network. The second set of listeners retrieve from the cache. |
|
I agree that it would make sense for the second set of listeners to receive cached data, but why does it show up in the WebSocket traffic in the Dev Tools? Is this an SDK issue? Is it not using the cache it ought to be? |
|
Actually, I suspect the second set of listeners would receive cached data if the first listener was attached with |
|
@davideast I've had a bit of a poke around with this and there's another plunk here that demonstrates the differences in behaviour between overlapping and non-overlapping listeners. It seems that if the listeners don't overlap, data for the second listener is re-retrieved via the WebSocket - which is the behaviour that I see with the current |
|
@cartant I went and spoke with a member on the Database team and your suspicions are correct. A This should PR should fix these issues. Thank you :) |
|
@davideast Thanks for looking further into it. What you say makes sense and fits with the behaviour I see. I'm looking forward to the performance improvements that should come with the next release. |
Closes #819
Checklist
npm install,npm run build, andnpm testrun successfully? yesDescription
This PR simplifies the list implementation so that only the reducers associated with the
child_added/remove/changedevents manipulate the list's internal array. Thevalueevent is only used to determine when the initial load has been done.The
on('value')andon('child_added', ...)calls are made within the same turn through the event loop, so only a single copy of the initial content is retrieved.The comments made in the commit that introduced this retrieve-the-initial-content-twice behaviour mention SDK quirks and nuances. By using only the
child_XXXevents and by not worrying whether thechild_addedevent adds the last key before or after thevalueevent fires, this PR's implementation should be sufficiently robust to cope with said quirks and nuances.