Skip to content

Commit f32f8ef

Browse files
cgc stats corrected
1 parent be5fc55 commit f32f8ef

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

src/codegraphcontext/cli/cli_helpers.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -572,28 +572,25 @@ def stats_helper(path: str = None):
572572
console.print("[cyan]📊 Overall Database Statistics[/cyan]\n")
573573

574574
with db_manager.get_driver().session() as session:
575-
# Get overall counts
575+
# Get overall counts using separate queries to avoid empty results
576+
# when some node types don't exist
576577
stats_query = """
577578
MATCH (r:Repository)
578-
WITH count(r) as repo_count
579-
MATCH (f:File)
580-
WITH repo_count, count(f) as file_count
581-
MATCH (func:Function)
582-
WITH repo_count, file_count, count(func) as function_count
583-
MATCH (cls:Class)
584-
WITH repo_count, file_count, function_count, count(cls) as class_count
585-
MATCH (m:Module)
579+
OPTIONAL MATCH (f:File)
580+
OPTIONAL MATCH (func:Function)
581+
OPTIONAL MATCH (cls:Class)
582+
OPTIONAL MATCH (m:Module)
586583
RETURN
587-
repo_count,
588-
file_count,
589-
function_count,
590-
class_count,
591-
count(m) as module_count
584+
count(DISTINCT r) as repo_count,
585+
count(DISTINCT f) as file_count,
586+
count(DISTINCT func) as function_count,
587+
count(DISTINCT cls) as class_count,
588+
count(DISTINCT m) as module_count
592589
"""
593590
result = session.run(stats_query)
594591
record = result.single()
595592

596-
if record:
593+
if record and record["repo_count"] > 0:
597594
table = Table(show_header=True, header_style="bold magenta")
598595
table.add_column("Metric", style="cyan")
599596
table.add_column("Count", style="green", justify="right")

0 commit comments

Comments
 (0)