* Get graph statistics
()
| 5938 | * Get graph statistics |
| 5939 | */ |
| 5940 | getStats(): GraphStats { |
| 5941 | // Single query for all three aggregate counts |
| 5942 | const counts = this.db.prepare(` |
| 5943 | SELECT |
| 5944 | (SELECT COUNT(*) FROM nodes) AS node_count, |
| 5945 | (SELECT COUNT(*) FROM edges) AS edge_count, |
| 5946 | (SELECT COUNT(*) FROM files) AS file_count |
| 5947 | `).get() as { node_count: number; edge_count: number; file_count: number }; |
| 5948 | |
| 5949 | const nodesByKind = {} as Record<NodeKind, number>; |
| 5950 | const nodeKindRows = this.db |
| 5951 | .prepare('SELECT kind, COUNT(*) as count FROM nodes GROUP BY kind') |
| 5952 | .all() as Array<{ kind: string; count: number }>; |
| 5953 | for (const row of nodeKindRows) { |
| 5954 | nodesByKind[row.kind as NodeKind] = row.count; |
| 5955 | } |
| 5956 | |
| 5957 | const edgesByKind = {} as Record<EdgeKind, number>; |
| 5958 | const edgeKindRows = this.db |
| 5959 | .prepare('SELECT kind, COUNT(*) as count FROM edges GROUP BY kind') |
| 5960 | .all() as Array<{ kind: string; count: number }>; |
| 5961 | for (const row of edgeKindRows) { |
| 5962 | edgesByKind[row.kind as EdgeKind] = row.count; |
| 5963 | } |
| 5964 | |
| 5965 | const filesByLanguage = {} as Record<Language, number>; |
| 5966 | const languageRows = this.db |
| 5967 | .prepare('SELECT language, COUNT(*) as count FROM files GROUP BY language') |
| 5968 | .all() as Array<{ language: string; count: number }>; |
| 5969 | for (const row of languageRows) { |
| 5970 | filesByLanguage[row.language as Language] = row.count; |
| 5971 | } |
| 5972 | |
| 5973 | return { |
| 5974 | nodeCount: counts.node_count, |
| 5975 | edgeCount: counts.edge_count, |
| 5976 | fileCount: counts.file_count, |
| 5977 | nodesByKind, |
| 5978 | edgesByKind, |
| 5979 | filesByLanguage, |
| 5980 | dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize() |
| 5981 | walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes() |
| 5982 | lastUpdated: Date.now(), |
| 5983 | }; |
| 5984 | } |
| 5985 | |
| 5986 | // =========================================================================== |
| 5987 | // Project Metadata |
no test coverage detected