FirebaseExtended / FirebaseExtended/firestore-leaderboards-codelab
Issue with Count within Collection on Leaderboard code
- Dominant language
- JavaScript
- Stars
- 5
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I stepped through the code and discovered a mistake in the algorithm. This is in particular for the n-ary tree realtime approach. The problem is that within the writeScoreToCollection function you need to remember to execute the pendingWrites even if no appropriate range was found and we have to create our own exact value document (this is the last line of the function).
If you want to use an example, take the following Data added to the tree (with min = 0 max = 1000)
userID: "A", score: 608
- This will just create a document under "scores"
userID: "B", score: 427
- This will combine the document with 608 document to form one bucket with range: 333.3 - 666.6 and count: 2
userID: "C", score: 516
- Here, we recurse into the writeScoreToCollection method once again (and properly CONSTRUCT the pendingWrite to update the count for this bucket). but alas, because of the fact that the snapshot is not empty (base case), and also we're not combining this document with another document, we never actually choose to execute all of the pending writes.
Please fix. thanks.
Contributor guide
Research direction
Find the n-ary tree realtime implementation and start at writeScoreToCollection. Reproduce the min=0, max=1000 sequence for users A (608), B (427), and C (516), then trace pendingWrites when no range is combined and an exact-value document is created. Done means the bucket count is updated for the third score and all pending writes are executed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100