* Get graph statistics
()
| 2422 | * Get graph statistics |
| 2423 | */ |
| 2424 | getStats(): GraphStats { |
| 2425 | // Single query for all three aggregate counts |
| 2426 | const counts = this.db.prepare(` |
| 2427 | SELECT |
| 2428 | (SELECT COUNT(*) FROM nodes) AS node_count, |
| 2429 | (SELECT COUNT(*) FROM edges) AS edge_count, |
| 2430 | (SELECT COUNT(*) FROM files) AS file_count |
| 2431 | `).get() as { node_count: number; edge_count: number; file_count: number }; |
| 2432 | |
| 2433 | const nodesByKind = {} as Record<NodeKind, number>; |
| 2434 | const nodeKindRows = this.db |
| 2435 | .prepare('SELECT kind, COUNT(*) as count FROM nodes GROUP BY kind') |
| 2436 | .all() as Array<{ kind: string; count: number }>; |
| 2437 | for (const row of nodeKindRows) { |
| 2438 | nodesByKind[row.kind as NodeKind] = row.count; |
| 2439 | } |
| 2440 | |
| 2441 | const edgesByKind = {} as Record<EdgeKind, number>; |
| 2442 | const edgeKindRows = this.db |
| 2443 | .prepare('SELECT kind, COUNT(*) as count FROM edges GROUP BY kind') |
| 2444 | .all() as Array<{ kind: string; count: number }>; |
| 2445 | for (const row of edgeKindRows) { |
| 2446 | edgesByKind[row.kind as EdgeKind] = row.count; |
| 2447 | } |
| 2448 | |
| 2449 | const filesByLanguage = {} as Record<Language, number>; |
| 2450 | const languageRows = this.db |
| 2451 | .prepare('SELECT language, COUNT(*) as count FROM files GROUP BY language') |
| 2452 | .all() as Array<{ language: string; count: number }>; |
| 2453 | for (const row of languageRows) { |
| 2454 | filesByLanguage[row.language as Language] = row.count; |
| 2455 | } |
| 2456 | |
| 2457 | return { |
| 2458 | nodeCount: counts.node_count, |
| 2459 | edgeCount: counts.edge_count, |
| 2460 | fileCount: counts.file_count, |
| 2461 | nodesByKind, |
| 2462 | edgesByKind, |
| 2463 | filesByLanguage, |
| 2464 | dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize() |
| 2465 | walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes() |
| 2466 | lastUpdated: Date.now(), |
| 2467 | }; |
| 2468 | } |
| 2469 | |
| 2470 | // =========================================================================== |
| 2471 | // Project Metadata |
no test coverage detected