(
plugin: RNPlugin,
documentId: string,
)
| 130 | * @param graphRemId The Rem ID of the graph widget (used as storage key) |
| 131 | */ |
| 132 | export async function generateAndStoreGraphData( |
| 133 | plugin: RNPlugin, |
| 134 | documentId: string, |
| 135 | ): Promise<PriorityGraphData> { |
| 136 | // 1. Build the document scope |
| 137 | const documentScope = await buildDocumentScope(plugin as any, documentId); |
| 138 | |
| 139 | // 2. Get ALL IncRems and card infos from the KB cache |
| 140 | const allIncRems = (await plugin.storage.getSession<IncrementalRem[]>(allIncrementalRemKey)) || []; |
| 141 | const allCardInfos = (await plugin.storage.getSession<CardPriorityInfo[]>(allCardPriorityInfoKey)) || []; |
| 142 | |
| 143 | // 3. Filter to document scope |
| 144 | const docIncRems = allIncRems.filter(r => documentScope.has(r.remId)); |
| 145 | const docCardInfos = allCardInfos.filter(c => documentScope.has(c.remId)); |
| 146 | |
| 147 | // 4. Compute the graph data (doc-scoped items, KB-wide percentiles) |
| 148 | const graphData = computePriorityGraphData(docIncRems, docCardInfos, allIncRems, allCardInfos); |
| 149 | |
| 150 | // 5. Store in synced storage keyed by DOCUMENT ID |
| 151 | // We reuse the same prefix but append documentId, ensuring unique storage per document |
| 152 | await plugin.storage.setSynced(PRIORITY_GRAPH_DATA_KEY_PREFIX + documentId, graphData); |
| 153 | |
| 154 | return graphData; |
| 155 | } |
| 156 | |
| 157 |
no test coverage detected