This repository was archived by the owner on Sep 30, 2023. It is now read-only.
This repository was archived by the owner on Sep 30, 2023. It is now read-only.
If hash is not present, get() returns element at 0th index #42
Open
Description
This is the get() method in EventStore:
get (hash) {
return this.iterator({ gte: hash, limit: 1 }).collect()[0]
}
The get() method indirectly calls _read
method:
_read (ops, hash, amount, inclusive) {
// Find the index of the gt/lt hash, or start from the beginning of the array if not found
const index = ops.map((e) => e.hash).indexOf(hash)
let startIndex = Math.max(index, 0)
// If gte/lte is set, we include the given hash, if not, start from the next element
startIndex += inclusive ? 0 : 1
// Slice the array to its requested size
const res = ops.slice(startIndex).slice(0, amount)
return res
}
If you call this method with a hash (let's say "foobar") that's not present in the EventStore, you'll notice that _read
still returns the element at 0th index. We noticed this while using get() method in the FeedStore (https://github.com/orbitdb/orbit-db-feedstore/blob/main/src/FeedStore.js).
Metadata
Metadata
Assignees
Labels
No labels