Does firebase web client download data every time I subscribe for a certain database path?

Does firebase web client download data every time I subscribe for a certain database path?



In my angular app, I use AngularFire to access firebase realtime database.


AngularFire



I have following method to retrieve entities in a certain database path.


private db: AngularFireDatabase;

public getAll(): Observable<Item>
return this.db.list<Item>('some/db/path').valueChanges();



If I call above method multiple times, does the data get downloaded multiple times from server, or firebase client uses a local cache second time onward?



If data gets downloaded multiple times, is there any way I can instruct firebase client to use local caching?




1 Answer
1



The Firebase Realtime Database client deduplicates listeners. That means that:


this.db.list<Item>('some/db/path').valueChanges();
this.db.list<Item>('some/db/path').valueChanges();



The above code will only download the data once initially, and only download the delta once for each change.



Note that you can check this for yourself by looking at the Web Socket traffic in the network panel of your browser.





Thanks for the answer. Not directly related to this, but I have another doubt. If I have persistence enabled in an android client, if the data of a certain db path is already cached, When the android app is restarted, if I subscribe for value changes of that path, will firebase download all data of that path again, or will it only download the diff between the cache and the server?
– Lahiru Chandima
Sep 4 '18 at 14:59





It does a so-called delta-sync in that case. This means it calculates the hashes of data it has cached, and sends those to the server. The server then only sends data that was modified back. This approach is not guaranteed to be minimal (that would mean the client would have to send a hash of each value), but is typically a lot smaller than sending all data.
– Frank van Puffelen
Sep 4 '18 at 15:06





Good to hear that. Also, I read in several places that if I use keepSynced() for a certain path in an android client, firebase will download all data of that path in each app restart. But, according to this mechanism you described, there shouldn't be any need to do so. Am I correct?
– Lahiru Chandima
Sep 4 '18 at 15:14


keepSynced()





Correct. You can check the debug logs to see what actually happens on the wire. Especially the hashing is quite education, although a bit hard to follow.
– Frank van Puffelen
Sep 4 '18 at 16:54



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)