MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / getStats

Method getStats

src/db/queries.ts:2804–2848  ·  view source on GitHub ↗

* Get graph statistics

()

Source from the content-addressed store, hash-verified

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

Callers 5

recordIndexEventFunction · 0.45
getToolsMethod · 0.45
handleExploreMethod · 0.45
handleStatusMethod · 0.45
mainFunction · 0.45

Calls 3

getMethod · 0.65
prepareMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected