Skip to content

Commit a302369

Browse files
committed
Add local DB stats helper for issue #469
1 parent f331ae6 commit a302369

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

scripts/show-db-stats.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
DB_PATH="${1:-$ROOT_DIR/standards_cache.sqlite}"
6+
7+
if [[ ! -f "$DB_PATH" ]]; then
8+
echo "Database not found: $DB_PATH" >&2
9+
exit 1
10+
fi
11+
12+
echo "Database: $DB_PATH"
13+
du -h "$DB_PATH"
14+
15+
"$ROOT_DIR/venv/bin/python" - "$DB_PATH" <<'PY'
16+
import os
17+
import sqlite3
18+
import sys
19+
20+
db_path = sys.argv[1]
21+
conn = sqlite3.connect(db_path)
22+
cur = conn.cursor()
23+
24+
print(f"size_bytes {os.path.getsize(db_path)}")
25+
26+
tables = [
27+
"node",
28+
"cre",
29+
"cre_links",
30+
"cre_node_links",
31+
"embeddings",
32+
]
33+
34+
for table in tables:
35+
try:
36+
count = cur.execute(f"select count(*) from {table}").fetchone()[0]
37+
print(f"{table}_count {count}")
38+
except sqlite3.Error as exc:
39+
print(f"{table}_count unavailable ({exc})")
40+
41+
try:
42+
standards = cur.execute(
43+
"""
44+
select name, count(*)
45+
from node
46+
where name is not null
47+
group by name
48+
order by count(*) desc, name asc
49+
limit 15
50+
"""
51+
).fetchall()
52+
print("top_standards")
53+
for name, count in standards:
54+
print(f"{name}\t{count}")
55+
except sqlite3.Error as exc:
56+
print(f"top_standards unavailable ({exc})")
57+
58+
conn.close()
59+
PY

0 commit comments

Comments
 (0)