perf: complete persist-load P2 hydration pass

This commit is contained in:
Youzini-afk
2026-04-22 19:31:44 +08:00
parent 37c6266a81
commit e880fe0b39
10 changed files with 1037 additions and 23 deletions

View File

@@ -10,6 +10,7 @@ import {
} from "../graph/knowledge-state.js";
import {
createDefaultTimelineState,
normalizeTimelineState,
normalizeGraphStoryTimeline,
} from "../graph/story-timeline.js";
import {
@@ -224,10 +225,12 @@ function getRequiredJournalCoverageStartFloor(graph, journals = []) {
return null;
}
export function normalizeGraphRuntimeState(graph, chatId = "") {
export function normalizeGraphRuntimeState(graph, chatId = "", options = {}) {
if (!graph || typeof graph !== "object") {
return graph;
}
const skipRecordFieldNormalization =
options?.skipRecordFieldNormalization === true;
const hadSummaryState =
graph.summaryState &&
typeof graph.summaryState === "object" &&
@@ -475,10 +478,10 @@ export function normalizeGraphRuntimeState(graph, chatId = "") {
graph.historyState = historyState;
graph.vectorIndexState = vectorIndexState;
if (Array.isArray(graph.nodes)) {
if (!skipRecordFieldNormalization && Array.isArray(graph.nodes)) {
graph.nodes.forEach((node) => normalizeNodeMemoryScope(node));
}
if (Array.isArray(graph.edges)) {
if (!skipRecordFieldNormalization && Array.isArray(graph.edges)) {
graph.edges.forEach((edge) => normalizeEdgeMemoryScope(edge));
}
graph.batchJournal = Array.isArray(graph.batchJournal)
@@ -496,10 +499,16 @@ export function normalizeGraphRuntimeState(graph, chatId = "") {
: createDefaultMaintenanceJournal();
graph.knowledgeState = createDefaultKnowledgeState(graph.knowledgeState);
graph.regionState = createDefaultRegionState(graph.regionState);
graph.timelineState = createDefaultTimelineState(graph.timelineState);
graph.timelineState = skipRecordFieldNormalization
? normalizeTimelineState(graph.timelineState)
: createDefaultTimelineState(graph.timelineState);
graph.summaryState = createDefaultSummaryState(graph.summaryState);
normalizeGraphCognitiveState(graph);
normalizeGraphStoryTimeline(graph);
if (skipRecordFieldNormalization) {
graph.timelineState = normalizeTimelineState(graph.timelineState);
} else {
normalizeGraphStoryTimeline(graph);
}
normalizeGraphSummaryState(graph);
if (!hadSummaryState) {
importLegacySynopsisToSummaryState(graph);