Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

local storage: iterate nodes from newest to oldest #410

Merged
merged 2 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions archaeologist/src/storage_api_browser_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class Iterator implements INodeIterator {
if (this.index >= nids.length) {
return null
}
const nid: Nid = nids[this.index]
const nid: Nid = nids[nids.length - this.index - 1]
const yek: NidToNodeYek = { yek: { kind: 'nid->node', key: nid } }
const lav: NidToNodeLav | undefined = await this.store.get(yek)
if (lav == null) {
Expand Down Expand Up @@ -622,7 +622,7 @@ export async function getAllNids(
return []
}
const value: Nid[] = lav.lav.value
return value
return value.reverse()
}

export function makeBrowserExtStorageApi(
Expand Down
3 changes: 3 additions & 0 deletions smuggler-api/src/node_slice_iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { TNode, OriginId } from './types'
import type { Optional } from 'armoury'

export interface INodeIterator {
/**
* @summary Iterate from most recently created nodes to the oldest
*/
next: () => Promise<Optional<TNode>>
total: () => number
abort: () => void
Expand Down
3 changes: 3 additions & 0 deletions smuggler-api/src/storage_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ export type StorageApi = {
args: NodeGetByOriginArgs,
signal?: AbortSignal
) => Promise<TNode[]>
/**
* @return Nids in the order from most recently created to the oldest
*/
getAllNids(args: NodeGetAllNidsArgs, signal?: AbortSignal): Promise<Nid[]>
update: (args: NodeUpdateArgs, signal?: AbortSignal) => Promise<Ack>
create: (
Expand Down