From aca6ee86b4fa9553230b4c383a867bb0a9d47cb2 Mon Sep 17 00:00:00 2001 From: Sergey Nikitin Date: Sat, 21 Jan 2023 19:25:07 +0000 Subject: [PATCH] local storage: iterate from newest to oldest nodes --- archaeologist/src/storage_api_browser_ext.ts | 4 ++-- smuggler-api/src/node_slice_iterator.ts | 3 +++ smuggler-api/src/storage_api.ts | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/archaeologist/src/storage_api_browser_ext.ts b/archaeologist/src/storage_api_browser_ext.ts index abe18008..a7ff1f09 100644 --- a/archaeologist/src/storage_api_browser_ext.ts +++ b/archaeologist/src/storage_api_browser_ext.ts @@ -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) { @@ -622,7 +622,7 @@ export async function getAllNids( return [] } const value: Nid[] = lav.lav.value - return value + return value.reverse() } export function makeBrowserExtStorageApi( diff --git a/smuggler-api/src/node_slice_iterator.ts b/smuggler-api/src/node_slice_iterator.ts index 8608e298..1974a529 100644 --- a/smuggler-api/src/node_slice_iterator.ts +++ b/smuggler-api/src/node_slice_iterator.ts @@ -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> total: () => number abort: () => void diff --git a/smuggler-api/src/storage_api.ts b/smuggler-api/src/storage_api.ts index ef82606d..f1532c9d 100644 --- a/smuggler-api/src/storage_api.ts +++ b/smuggler-api/src/storage_api.ts @@ -98,6 +98,9 @@ export type StorageApi = { args: NodeGetByOriginArgs, signal?: AbortSignal ) => Promise + /** + * @return Nids in the order from most recently created to the oldest + */ getAllNids(args: NodeGetAllNidsArgs, signal?: AbortSignal): Promise update: (args: NodeUpdateArgs, signal?: AbortSignal) => Promise create: (