* Get graph statistics
()
| 5819 | * Get graph statistics |
| 5820 | */ |
| 5821 | getStats(): GraphStats { |
| 5822 | // Single query for all three aggregate counts |
| 5823 | const counts = this.db.prepare(` |
| 5824 | SELECT |
| 5825 | (SELECT COUNT(*) FROM nodes) AS node_count, |
| 5826 | (SELECT COUNT(*) FROM edges) AS edge_count, |
| 5827 | (SELECT COUNT(*) FROM files) AS file_count |
| 5828 | `).get() as { node_count: number; edge_count: number; file_count: number }; |
| 5829 | |
| 5830 | const nodesByKind = {} as Record<NodeKind, number>; |
| 5831 | const nodeKindRows = this.db |
| 5832 | .prepare('SELECT kind, COUNT(*) as count FROM nodes GROUP BY kind') |
| 5833 | .all() as Array<{ kind: string; count: number }>; |
| 5834 | for (const row of nodeKindRows) { |
| 5835 | nodesByKind[row.kind as NodeKind] = row.count; |
| 5836 | } |
| 5837 | |
| 5838 | const edgesByKind = {} as Record<EdgeKind, number>; |
| 5839 | const edgeKindRows = this.db |
| 5840 | .prepare('SELECT kind, COUNT(*) as count FROM edges GROUP BY kind') |
| 5841 | .all() as Array<{ kind: string; count: number }>; |
| 5842 | for (const row of edgeKindRows) { |
| 5843 | edgesByKind[row.kind as EdgeKind] = row.count; |
| 5844 | } |
| 5845 | |
| 5846 | const filesByLanguage = {} as Record<Language, number>; |
| 5847 | const languageRows = this.db |
| 5848 | .prepare('SELECT language, COUNT(*) as count FROM files GROUP BY language') |
| 5849 | .all() as Array<{ language: string; count: number }>; |
| 5850 | for (const row of languageRows) { |
| 5851 | filesByLanguage[row.language as Language] = row.count; |
| 5852 | } |
| 5853 | |
| 5854 | return { |
| 5855 | nodeCount: counts.node_count, |
| 5856 | edgeCount: counts.edge_count, |
| 5857 | fileCount: counts.file_count, |
| 5858 | nodesByKind, |
| 5859 | edgesByKind, |
| 5860 | filesByLanguage, |
| 5861 | dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize() |
| 5862 | walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes() |
| 5863 | lastUpdated: Date.now(), |
| 5864 | }; |
| 5865 | } |
| 5866 | |
| 5867 | // =========================================================================== |
| 5868 | // Project Metadata |
no test coverage detected