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

Method getStats

src/db/queries.ts:5821–5865  ·  view source on GitHub ↗

* Get graph statistics

()

Source from the content-addressed store, hash-verified

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

Callers 12

recordIndexEventFunction · 0.45
getToolsMethod · 0.45
handleExploreMethod · 0.45
handleStatusMethod · 0.45
buildFlowFunction · 0.45
buildMapFunction · 0.45
buildStatsFunction · 0.45
buildScreensFunction · 0.45
buildStepsFunction · 0.45
buildEntryPointsFunction · 0.45
buildRoutesFunction · 0.45
mainFunction · 0.45

Calls 3

getMethod · 0.65
prepareMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected