* Get graph statistics
()
| 2802 | * Get graph statistics |
| 2803 | */ |
| 2804 | getStats(): GraphStats { |
| 2805 | // Single query for all three aggregate counts |
| 2806 | const counts = this.db.prepare(` |
| 2807 | SELECT |
| 2808 | (SELECT COUNT(*) FROM nodes) AS node_count, |
| 2809 | (SELECT COUNT(*) FROM edges) AS edge_count, |
| 2810 | (SELECT COUNT(*) FROM files) AS file_count |
| 2811 | `).get() as { node_count: number; edge_count: number; file_count: number }; |
| 2812 | |
| 2813 | const nodesByKind = {} as Record<NodeKind, number>; |
| 2814 | const nodeKindRows = this.db |
| 2815 | .prepare('SELECT kind, COUNT(*) as count FROM nodes GROUP BY kind') |
| 2816 | .all() as Array<{ kind: string; count: number }>; |
| 2817 | for (const row of nodeKindRows) { |
| 2818 | nodesByKind[row.kind as NodeKind] = row.count; |
| 2819 | } |
| 2820 | |
| 2821 | const edgesByKind = {} as Record<EdgeKind, number>; |
| 2822 | const edgeKindRows = this.db |
| 2823 | .prepare('SELECT kind, COUNT(*) as count FROM edges GROUP BY kind') |
| 2824 | .all() as Array<{ kind: string; count: number }>; |
| 2825 | for (const row of edgeKindRows) { |
| 2826 | edgesByKind[row.kind as EdgeKind] = row.count; |
| 2827 | } |
| 2828 | |
| 2829 | const filesByLanguage = {} as Record<Language, number>; |
| 2830 | const languageRows = this.db |
| 2831 | .prepare('SELECT language, COUNT(*) as count FROM files GROUP BY language') |
| 2832 | .all() as Array<{ language: string; count: number }>; |
| 2833 | for (const row of languageRows) { |
| 2834 | filesByLanguage[row.language as Language] = row.count; |
| 2835 | } |
| 2836 | |
| 2837 | return { |
| 2838 | nodeCount: counts.node_count, |
| 2839 | edgeCount: counts.edge_count, |
| 2840 | fileCount: counts.file_count, |
| 2841 | nodesByKind, |
| 2842 | edgesByKind, |
| 2843 | filesByLanguage, |
| 2844 | dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize() |
| 2845 | walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes() |
| 2846 | lastUpdated: Date.now(), |
| 2847 | }; |
| 2848 | } |
| 2849 | |
| 2850 | // =========================================================================== |
| 2851 | // Project Metadata |
no test coverage detected