homepage
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user