mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Merge branch 'main' into helia
This commit is contained in:
commit
9f766da793
@ -434,7 +434,7 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora
|
|||||||
|
|
||||||
if (useBuffer) {
|
if (useBuffer) {
|
||||||
const endIndex = buffer.keys.length
|
const endIndex = buffer.keys.length
|
||||||
const startIndex = endIndex - amount
|
const startIndex = endIndex > amount ? endIndex - amount : 0
|
||||||
const keys = buffer.keys.slice(startIndex, endIndex)
|
const keys = buffer.keys.slice(startIndex, endIndex)
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
const hash = buffer.get(key)
|
const hash = buffer.get(key)
|
||||||
|
@ -40,6 +40,7 @@ describe('Log - Iterator', function () {
|
|||||||
let startHash
|
let startHash
|
||||||
const hashes = []
|
const hashes = []
|
||||||
const logSize = 100
|
const logSize = 100
|
||||||
|
const startIndex = 67
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
log1 = await Log(testIdentity, { logId: 'X' })
|
log1 = await Log(testIdentity, { logId: 'X' })
|
||||||
@ -51,8 +52,8 @@ describe('Log - Iterator', function () {
|
|||||||
|
|
||||||
// entry67
|
// entry67
|
||||||
// startHash = 'zdpuAxCuaH2R7AYKZ6ZBeeA94v3FgmHZ8wCfDy7pLVcoc3zSo'
|
// startHash = 'zdpuAxCuaH2R7AYKZ6ZBeeA94v3FgmHZ8wCfDy7pLVcoc3zSo'
|
||||||
startHash = hashes[67][0]
|
startHash = hashes[startIndex][0]
|
||||||
strictEqual(startHash, hashes[67][0])
|
strictEqual(startHash, hashes[startIndex][0])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns length with lte and amount', async () => {
|
it('returns length with lte and amount', async () => {
|
||||||
@ -368,6 +369,40 @@ describe('Log - Iterator', function () {
|
|||||||
strictEqual(i, 68)
|
strictEqual(i, 68)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('returns correct entries with gt when amount is more than total entries', async () => {
|
||||||
|
const amount = logSize - startIndex
|
||||||
|
const expectedAmount = logSize - startIndex - 1
|
||||||
|
|
||||||
|
const it = log1.iterator({
|
||||||
|
gt: startHash,
|
||||||
|
amount
|
||||||
|
})
|
||||||
|
|
||||||
|
let i = 0
|
||||||
|
for await (const entry of it) {
|
||||||
|
strictEqual(entry.payload, 'entry' + (logSize - 1 - i++))
|
||||||
|
}
|
||||||
|
|
||||||
|
strictEqual(i, expectedAmount)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns correct entries with gte when amount is more than total entries', async () => {
|
||||||
|
const amount = logSize - startIndex + 1
|
||||||
|
const expectedAmount = amount - 1
|
||||||
|
|
||||||
|
const it = log1.iterator({
|
||||||
|
gte: startHash,
|
||||||
|
amount
|
||||||
|
})
|
||||||
|
|
||||||
|
let i = 0
|
||||||
|
for await (const entry of it) {
|
||||||
|
strictEqual(entry.payload, 'entry' + (logSize - 1 - i++))
|
||||||
|
}
|
||||||
|
|
||||||
|
strictEqual(i, expectedAmount)
|
||||||
|
})
|
||||||
|
|
||||||
it('returns zero entries when amount is 0', async () => {
|
it('returns zero entries when amount is 0', async () => {
|
||||||
const it = log1.iterator({
|
const it = log1.iterator({
|
||||||
amount: 0
|
amount: 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user