Adds Firebase API read-through caching (fixes #25) #26
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.
This change adds support for a read-through caching adapter on top of the Firebase API that fixes #25. It enables support for caching comment-threads and other non-UI content responses being returned from Firebase for
react-hnviews. We use localForage/IDB for the caching layer, falling back to localStorage.This change uses https://github.com/GoogleChrome/firetruck (not yet public, but going through Google open-source releasing atm). Both @insin and @NekR should have access to look at what's there atm. It's not particularly fancy. The adapter doesn't yet support
set()operations but since this project is mostly just reading HN data, I think we should be fine.DevTools > Resources > IndexedDB showing records cached:
Here's a demo of a built version of the app still being able to view comments when the network is killed:
📹 https://www.youtube.com/watch?v=Nz_f9Gfii6w&feature=youtu.be
There are quite a few perf improvements that can be made to Firetruck (we start to hit slow reads when you're looking at large (e.g 300+) comment threads and could optimize bottlenecks like
JSON.stringify(), but I can look at that next. Consider this a better-than-what-we-have-now addition :)Things we can/should do better in future
setthat won't be cached and provide a meaningful message. Even better would be scheduling writes, but again, React HN doesn't really need this