This commit is contained in:
schmeeve
2026-09-23 13:01:22 -07:00
parent 220991de09
commit 35c71a1e6d
4 changed files with 80 additions and 0 deletions

View File

@@ -346,6 +346,36 @@ async def _record_history(
)
async def get_homepage_stats() -> dict:
from pathlib import Path
async with aiosqlite.connect(settings.database_path) as db:
db.row_factory = aiosqlite.Row
async def count(query: str) -> int:
row = await db.execute(query)
row = await row.fetchone()
return row[0]
total_notes = await count("SELECT COUNT(*) FROM notes WHERE deleted_at IS NULL")
actions = await count("SELECT COUNT(*) FROM history")
users = await count("SELECT COUNT(*) FROM users")
attachments = 0
data_root = Path(settings.data_dir)
if data_root.is_dir():
for attach_dir in data_root.rglob("attachments"):
if attach_dir.is_dir():
attachments += sum(1 for f in attach_dir.iterdir() if f.is_file())
return {
"total_notes": total_notes,
"attachments": attachments,
"actions": actions,
"users": users,
}
async def get_history(note_id: str) -> list[dict]:
async with aiosqlite.connect(settings.database_path) as db:
db.row_factory = aiosqlite.Row