Skip to content

Commit bc0c716

Browse files
committed
replace .all() with .iter(), hoping this helps with memory blowup
1 parent a8a9736 commit bc0c716

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

packages/memory/space-schema.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,18 +348,16 @@ function addToSelection(
348348
}
349349

350350
// Get the ValueEntry objects for the facts that match our selector
351-
function getMatchingFacts<Space extends MemorySpace>(
351+
function* getMatchingFacts<Space extends MemorySpace>(
352352
session: SpaceStoreSession<Space>,
353353
factSelector: FactSelector,
354354
): Iterable<IAttestation & { cause: CauseString; since: number }> {
355-
const results = [];
356355
for (const fact of selectFacts(session, factSelector)) {
357-
results.push({
356+
yield {
358357
value: fact.is,
359358
address: { id: fact.of, type: fact.the, path: [] },
360359
cause: fact.cause,
361360
since: fact.since,
362-
});
361+
};
363362
}
364-
return results;
365363
}

packages/memory/space.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -570,15 +570,16 @@ export const selectFacts = function* <Space extends MemorySpace>(
570570
{ store }: Session<Space>,
571571
{ the, of, cause, is, since }: FactSelector,
572572
): Iterable<SelectedFact> {
573-
const rows = store.prepare(EXPORT).all({
574-
the: the === SelectAllString ? null : the,
575-
of: of === SelectAllString ? null : of,
576-
cause: cause === SelectAllString ? null : cause,
577-
is: is === undefined ? null : {},
578-
since: since ?? null,
579-
}) as StateRow[];
580-
581-
for (const row of rows) {
573+
const stmt = store.prepare(EXPORT);
574+
for (
575+
const row of stmt.iter({
576+
the: the === SelectAllString ? null : the,
577+
of: of === SelectAllString ? null : of,
578+
cause: cause === SelectAllString ? null : cause,
579+
is: is === undefined ? null : {},
580+
since: since ?? null,
581+
}) as Iterable<StateRow>
582+
) {
582583
yield toFact(row);
583584
}
584585
};
@@ -587,14 +588,19 @@ export const selectFact = function <Space extends MemorySpace>(
587588
{ store }: Session<Space>,
588589
{ the, of, since }: { the: MIME; of: URI; since?: number },
589590
): SelectedFact | undefined {
590-
const rows = store.prepare(EXPORT).all({
591-
the: the,
592-
of: of,
593-
cause: null,
594-
is: null,
595-
since: since ?? null,
596-
}) as StateRow[];
597-
return (rows.length > 0) ? toFact(rows[0]) : undefined;
591+
const stmt = store.prepare(EXPORT);
592+
for (
593+
const row of stmt.iter({
594+
the: the,
595+
of: of,
596+
cause: null,
597+
is: null,
598+
since: since ?? null,
599+
}) as Iterable<StateRow>
600+
) {
601+
return toFact(row);
602+
}
603+
return undefined;
598604
};
599605

600606
/**

0 commit comments

Comments
 (0)