tag clouds by user space

This commit is contained in:
2026-09-24 13:57:34 -07:00
parent 832168e845
commit 32f382353e
2 changed files with 13 additions and 4 deletions

View File

@@ -315,14 +315,23 @@ async def _attach_meta(notes: list[dict]) -> None:
note.pop("path", None)
async def tag_counts() -> list[dict]:
async def tag_counts(username: str) -> list[dict]:
async with aiosqlite.connect(settings.database_path) as db:
db.row_factory = aiosqlite.Row
names = (
[username, settings.common_space]
if username != settings.common_space
else [settings.common_space]
)
placeholders = ",".join("?" for _ in names)
rows = await db.execute(
"SELECT t.name, COUNT(nt.note_id) AS count"
" FROM tags t JOIN note_tags nt ON nt.tag_id = t.id"
" JOIN notes n ON n.id = nt.note_id AND n.deleted_at IS NULL"
" GROUP BY t.id ORDER BY count DESC, t.name LIMIT 50"
" JOIN users u ON u.id = n.user_id"
f" WHERE u.name IN ({placeholders})"
" GROUP BY t.id ORDER BY count DESC, t.name LIMIT 50",
names,
)
return [dict(r) for r in await rows.fetchall()]