mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
perf(evidence): bound temporary storage for filtered unknown pages (#15747)
This commit is contained in:
1 parent
11ff41ddbb
commit
8dc37bfcea
2 files changed
+66
-18
No files matched your search
@@ -295,6 +295,59 @@ describe("residual unknown dependency histories", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("pages combined Unknown filters in ID order and sees revised heads", () => {
|
||||
const store = ledger();
|
||||
const rows = Array.from({ length: 12 }, (_, index) => {
|
||||
const result = store.recordUnknown(
|
||||
input(`Question ${String(index)}`, {
|
||||
domain: index < 8 ? "protocol" : "other",
|
||||
severity: index % 2 === 0 ? "high" : "low",
|
||||
}),
|
||||
mutation(`page-${String(index)}`),
|
||||
);
|
||||
if (!result.ok) throw result.error;
|
||||
return result.value;
|
||||
});
|
||||
const matches = [rows[0]!, rows[2]!, rows[4]!, rows[6]!].sort((left, right) =>
|
||||
left.unknown_id.localeCompare(right.unknown_id),
|
||||
);
|
||||
const query = {
|
||||
status: "open",
|
||||
severity: "high",
|
||||
domain: "protocol",
|
||||
} as const;
|
||||
expect(store.listUnknownsPage({ ...query, offset: 1, limit: 1 })).toEqual({
|
||||
items: matches.slice(1, 2),
|
||||
total: 4,
|
||||
offset: 1,
|
||||
next_offset: 2,
|
||||
});
|
||||
expect(store.listUnknownsPage({ ...query, offset: 4, limit: 1 })).toEqual({
|
||||
items: [],
|
||||
total: 4,
|
||||
offset: 4,
|
||||
next_offset: null,
|
||||
});
|
||||
expect(store.listUnknownsPage({ ...query, offset: 9, limit: 1 })).toEqual({
|
||||
items: [],
|
||||
total: 4,
|
||||
offset: 9,
|
||||
next_offset: null,
|
||||
});
|
||||
expect(
|
||||
store.updateUnknown(update(matches[0]!), mutation("page-revision")).ok,
|
||||
).toBe(true);
|
||||
expect(store.listUnknownsPage({ ...query, limit: 1 })).toEqual({
|
||||
items: matches.slice(1, 2),
|
||||
total: 3,
|
||||
offset: 0,
|
||||
next_offset: 1,
|
||||
});
|
||||
expect(
|
||||
store.listUnknowns({ ...query, status: "investigating" }),
|
||||
).toMatchObject([{ unknown_id: matches[0]!.unknown_id, revision: 2 }]);
|
||||
});
|
||||
|
||||
describe("residual unknown registry resolution and history", () => {
|
||||
it("rejects inference for observed resolution, then accepts matching live evidence", () => {
|
||||
const store = ledger();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { selectViewRows } from "../../domain/analysisView/selectViewRows.js";
|
||||
import type { EvidenceInspectionRecords } from "../../domain/evidenceRecordSummary.js";
|
||||
import { InvalidResidualUnknownGraphError } from "../../domain/residualUnknownGraphError.js";
|
||||
import { z } from "zod";
|
||||
@@ -552,30 +553,24 @@ export class EvidenceLedger {
|
||||
query.status === undefined &&
|
||||
query.severity === undefined &&
|
||||
query.domain === undefined;
|
||||
const matching = unfiltered
|
||||
? sorted
|
||||
: sorted.filter(
|
||||
(unknown) =>
|
||||
const { rows, total } = selectViewRows(
|
||||
sorted,
|
||||
{ offset, limit: query.limit ?? sorted.length },
|
||||
unfiltered
|
||||
? undefined
|
||||
: (unknown) =>
|
||||
(query.status === undefined || unknown.status === query.status) &&
|
||||
(query.severity === undefined ||
|
||||
unknown.severity === query.severity) &&
|
||||
(query.domain === undefined || unknown.domain === query.domain),
|
||||
);
|
||||
const start = Math.min(offset, matching.length);
|
||||
const end =
|
||||
query.limit === undefined
|
||||
? undefined
|
||||
: start + Math.min(query.limit, matching.length - start);
|
||||
const page = matching.slice(start, end);
|
||||
const nextOffset =
|
||||
offset <= matching.length && start + page.length < matching.length
|
||||
? start + page.length
|
||||
: null;
|
||||
(unknown) => structuredClone(unknown),
|
||||
);
|
||||
const end = offset + rows.length;
|
||||
return {
|
||||
items: page.map((unknown) => structuredClone(unknown)),
|
||||
total: matching.length,
|
||||
items: rows,
|
||||
total,
|
||||
offset,
|
||||
next_offset: nextOffset,
|
||||
next_offset: end < total ? end : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user