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

Method getStats

src/db/queries.ts:6272–6316  ·  view source on GitHub ↗

* Get graph statistics

()

Source from the content-addressed store, hash-verified

6270 * Get graph statistics
6271 */
6272 getStats(): GraphStats {
6273 // Single query for all three aggregate counts
6274 const counts = this.db.prepare(`
6275 SELECT
6276 (SELECT COUNT(*) FROM nodes) AS node_count,
6277 (SELECT COUNT(*) FROM edges) AS edge_count,
6278 (SELECT COUNT(*) FROM files) AS file_count
6279 `).get() as { node_count: number; edge_count: number; file_count: number };
6280
6281 const nodesByKind = {} as Record<NodeKind, number>;
6282 const nodeKindRows = this.db
6283 .prepare('SELECT kind, COUNT(*) as count FROM nodes GROUP BY kind')
6284 .all() as Array<{ kind: string; count: number }>;
6285 for (const row of nodeKindRows) {
6286 nodesByKind[row.kind as NodeKind] = row.count;
6287 }
6288
6289 const edgesByKind = {} as Record<EdgeKind, number>;
6290 const edgeKindRows = this.db
6291 .prepare('SELECT kind, COUNT(*) as count FROM edges GROUP BY kind')
6292 .all() as Array<{ kind: string; count: number }>;
6293 for (const row of edgeKindRows) {
6294 edgesByKind[row.kind as EdgeKind] = row.count;
6295 }
6296
6297 const filesByLanguage = {} as Record<Language, number>;
6298 const languageRows = this.db
6299 .prepare('SELECT language, COUNT(*) as count FROM files GROUP BY language')
6300 .all() as Array<{ language: string; count: number }>;
6301 for (const row of languageRows) {
6302 filesByLanguage[row.language as Language] = row.count;
6303 }
6304
6305 return {
6306 nodeCount: counts.node_count,
6307 edgeCount: counts.edge_count,
6308 fileCount: counts.file_count,
6309 nodesByKind,
6310 edgesByKind,
6311 filesByLanguage,
6312 dbSizeBytes: 0, // Set by caller using DatabaseConnection.getSize()
6313 walSizeBytes: 0, // Set by caller using DatabaseConnection.getWalSizeBytes()
6314 lastUpdated: Date.now(),
6315 };
6316 }
6317
6318 // ===========================================================================
6319 // 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