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

Commit 55a68ab

Browse files
committed
Merge branch 'rm-unused-slice-features' into offline-storage-api-2
2 parents f7daeca + 5d94d7c commit 55a68ab

File tree

8 files changed

+54
-34
lines changed

8 files changed

+54
-34
lines changed

archaeologist/src/background/suggestAssociations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export async function suggestAssociations(
77
limit?: number
88
): Promise<TNode[]> {
99
const beagle = Beagle.fromString(phrase)
10-
const iter = storage.node.slice({})
10+
const iter = storage.node.iterate()
1111
const suggested: TNode[] = []
1212
limit = limit ?? 8
1313
// FIXME(akindyakov): This is a dirty hack to limit time of search by limiting

archaeologist/src/omnibox/omnibox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const lookUpAndSuggestFor = lodash.debounce(
5252
suggest: (suggestResults: browser.Omnibox.SuggestResult[]) => void
5353
): Promise<void> => {
5454
const beagle = Beagle.fromString(text)
55-
const iter = storage.node.slice({})
55+
const iter = storage.node.iterate()
5656
const suggestions: browser.Omnibox.SuggestResult[] = []
5757
for (
5858
let node = await iter.next();

elementary/src/grid/SearchGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const SearchGrid = ({
7676
} | null>(null)
7777
useEffect(() => {
7878
setUpSearch({
79-
iter: storage.node.slice({}),
79+
iter: storage.node.iterate(),
8080
beagle: Beagle.fromString(q || undefined),
8181
})
8282
}, [q])

smuggler-api/src/api_datacenter.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
} from './types'
3434
import type {
3535
CreateNodeArgs,
36-
GetNodeSliceArgs,
3736
NodeBatchRequestBody,
3837
CreateEdgeArgs,
3938
StorageApi,
@@ -228,6 +227,25 @@ async function getNode({
228227
return node
229228
}
230229

230+
async function getNodesByOrigin({
231+
origin,
232+
}: {
233+
origin: OriginId
234+
signal?: AbortSignal
235+
}): Promise<TNode[]> {
236+
const sliceAll: GetNodeSliceArgs = {
237+
start_time: 0, // since the beginning of time
238+
bucket_time_size: 366 * 24 * 60 * 60,
239+
origin,
240+
}
241+
const ret: TNode[] = []
242+
const iter = _getNodesSliceIter(sliceAll)
243+
for (let node = await iter.next(); node != null; node = await iter.next()) {
244+
ret.push(node)
245+
}
246+
return ret
247+
}
248+
231249
async function getNodeBatch(
232250
req: NodeBatchRequestBody,
233251
signal?: AbortSignal
@@ -348,19 +366,23 @@ const getNodesSlice: GetNodesSliceFn = async ({
348366
}
349367
}
350368

369+
type GetNodeSliceArgs = {
370+
start_time?: number
371+
origin?: OriginId
372+
bucket_time_size?: number
373+
}
374+
351375
function _getNodesSliceIter({
352-
end_time,
353376
start_time,
354-
limit,
355377
origin,
356378
bucket_time_size,
357379
}: GetNodeSliceArgs) {
358380
return new TNodeSliceIterator(
359381
getNodesSlice,
360382
start_time,
361-
end_time,
383+
undefined,
362384
bucket_time_size,
363-
limit,
385+
undefined,
364386
origin
365387
)
366388
}
@@ -783,9 +805,10 @@ export function makeDatacenterStorageApi(): StorageApi {
783805
return {
784806
node: {
785807
get: getNode,
808+
getByOrigin: getNodesByOrigin,
786809
update: updateNode,
787810
create: createNode,
788-
slice: _getNodesSliceIter,
811+
iterate: () => _getNodesSliceIter({}),
789812
delete: deleteNode,
790813
bulkDelete: bulkDeleteNodes,
791814
batch: {

smuggler-api/src/node_slice_iterator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface INodeIterator {
55
next: () => Promise<Optional<TNode>>
66
total: () => number
77
exhausted: () => boolean
8-
abort(): void
8+
abort: () => void
99
}
1010

1111
export type GetNodesSliceFn = ({

smuggler-api/src/steroid/node.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,9 @@ export async function lookupNodes(
314314
return storage.node.get({ nid: key.nid, signal })
315315
} else if ('webBookmark' in key) {
316316
const { id, stableUrl } = genOriginId(key.webBookmark.url)
317-
const query = { ...SLICE_ALL, origin: { id } }
318-
const iter = storage.node.slice(query)
317+
const nodes: TNode[] = await storage.node.getByOrigin({ origin: { id } })
319318

320-
for (let node = await iter.next(); node != null; node = await iter.next()) {
319+
for (const node of nodes) {
321320
const nodeUrl = node.extattrs?.web?.url
322321
if (nodeUrl && stabiliseUrlForOriginId(nodeUrl) === stableUrl) {
323322
return node
@@ -326,34 +325,32 @@ export async function lookupNodes(
326325
return undefined
327326
} else if ('webQuote' in key) {
328327
const { id, stableUrl } = genOriginId(key.webQuote.url)
329-
const query = { ...SLICE_ALL, origin: { id } }
330-
const iter = storage.node.slice(query)
328+
const nodes: TNode[] = await storage.node.getByOrigin({ origin: { id } })
331329

332-
const nodes: TNode[] = []
333-
for (let node = await iter.next(); node != null; node = await iter.next()) {
330+
const ret: TNode[] = []
331+
for (const node of nodes) {
334332
if (NodeUtil.isWebQuote(node) && node.extattrs?.web_quote) {
335333
if (
336334
stabiliseUrlForOriginId(node.extattrs.web_quote.url) === stableUrl
337335
) {
338-
nodes.push(node)
336+
ret.push(node)
339337
}
340338
}
341339
}
342340
return nodes
343341
} else if ('url' in key) {
344342
const { id, stableUrl } = genOriginId(key.url)
345-
const query = { ...SLICE_ALL, origin: { id } }
346-
const iter = storage.node.slice(query)
343+
const nodes: TNode[] = await storage.node.getByOrigin({ origin: { id } })
347344

348-
const nodes: TNode[] = []
349-
for (let node = await iter.next(); node != null; node = await iter.next()) {
345+
const ret: TNode[] = []
346+
for (const node of nodes) {
350347
if (NodeUtil.isWebBookmark(node) && node.extattrs?.web) {
351348
if (stabiliseUrlForOriginId(node.extattrs.web.url) === stableUrl) {
352-
nodes.push(node)
349+
ret.push(node)
353350
}
354351
}
355352
}
356-
return nodes
353+
return ret
357354
}
358355

359356
throw new Error(`Failed to lookup nodes, unsupported key ${key}`)

smuggler-api/src/storage_api.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ export type CreateNodeArgs = {
3939
created_at?: Date
4040
}
4141

42-
export type GetNodeSliceArgs = {
43-
end_time?: number
44-
start_time?: number
45-
limit?: number
46-
origin?: OriginId
47-
bucket_time_size?: number
48-
}
49-
5042
export type NodeBatchRequestBody = {
5143
nids: Nid[]
5244
}
@@ -74,6 +66,13 @@ export type SwitchEdgeStickinessArgs = {
7466
export type StorageApi = {
7567
node: {
7668
get: ({ nid, signal }: { nid: Nid; signal?: AbortSignal }) => Promise<TNode>
69+
getByOrigin: ({
70+
origin,
71+
signal,
72+
}: {
73+
origin: OriginId
74+
signal?: AbortSignal
75+
}) => Promise<TNode[]>
7776
update: (
7877
args: { nid: Nid } & NodePatchRequest,
7978
signal?: AbortSignal
@@ -82,7 +81,7 @@ export type StorageApi = {
8281
args: CreateNodeArgs,
8382
signal?: AbortSignal
8483
) => Promise<NewNodeResponse>
85-
slice: (args: GetNodeSliceArgs) => INodeIterator
84+
iterate: () => INodeIterator
8685
delete: ({
8786
nid,
8887
signal,

smuggler-api/src/storage_api_throwing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export function makeAlwaysThrowingStorageApi(): StorageApi {
1414
return {
1515
node: {
1616
get: throwError,
17+
getByOrigin: throwError,
1718
update: throwError,
1819
create: throwError,
19-
slice: throwError,
20+
iterate: throwError,
2021
delete: throwError,
2122
bulkDelete: throwError,
2223
batch: {

0 commit comments

Comments
 (0)