Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: use between in getMiniblocks query #1302

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions packages/sdk/src/persistenceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from './streamUtils'

import { dlog, dlogError } from '@river-build/dlog'
import { isDefined } from './check'

const DEFAULT_RETRY_COUNT = 2
const log = dlog('csb:persistence')
Expand Down Expand Up @@ -202,22 +201,25 @@ export class PersistenceStore extends Dexie implements IPersistenceStore {
rangeStart: bigint,
rangeEnd: bigint,
): Promise<ParsedMiniblock[]> {
const ids: [string, string][] = []
for (let i = rangeStart; i <= rangeEnd; i++) {
ids.push([streamId, i.toString()])
}
const records = await this.miniblocks.bulkGet(ids)
const records = await this.miniblocks
.where('[streamId+miniblockNum]')
.between([streamId, rangeStart.toString()], [streamId, rangeEnd.toString()])
.toArray()

const miniblocks: ParsedMiniblock[] = []
// All or nothing
const miniblocks = records
.map((record) => {
if (!record) {
return undefined
}
const cachedMiniblock = PersistedMiniblock.fromBinary(record.data)
return persistedMiniblockToParsedMiniblock(cachedMiniblock)
})
.filter(isDefined)
return miniblocks.length === ids.length ? miniblocks : []
for (const record of records) {
if (!record) {
return []
}
const cachedMiniblock = PersistedMiniblock.fromBinary(record.data)
const parsedMiniblock = persistedMiniblockToParsedMiniblock(cachedMiniblock)
if (!parsedMiniblock) {
return []
}
miniblocks.push(parsedMiniblock)
}
return miniblocks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update this to miniblocks.length === (rangeEnd-rangeStart) ? miniblocks : []

}

private requestPersistentStorage() {
Expand Down
Loading