Implement Index Scanning by schmidt-sebastian · Pull Request #6008 · firebase/firebase-js-sdk (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if barriers[0] is larger than indexRange.upper, is that not possible?
I think we could do something like:
// Assume barriers is sorted, it is right?
let runningLower = indexRange.lower
let runningOpen = indexRange.lowerOpen
for(const barrier: barriers) {
if(barrier <= indexRange.lower) {continue;}
if(barrier >= indexRange.upper) {break;}
ranges.push([runningLower /*need to handle lowerOpen as well*/, barrier]);
runningLower = barrier
lowerOpen = true
}
// Handles last
ranges.push([runningLower, indexRange.upper])
You could even do handle this by taking IDBKeyRange[], sort both indexRanges and barriers together..then process from left to right. But maybe let's not go there, it should be rare in real world scenarios.