Fix anchors router to use get_anchors_paginated

Anchors are global, not user-specific. Added paginated db function.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
giles
2026-01-11 13:08:37 +00:00
parent 65169f49f9
commit c3d131644a
2 changed files with 23 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ async def list_anchors(
from fastapi.responses import RedirectResponse from fastapi.responses import RedirectResponse
return RedirectResponse(url="/login", status_code=302) return RedirectResponse(url="/login", status_code=302)
anchors = await db.get_user_anchors(username, offset=offset, limit=limit) anchors = await db.get_anchors_paginated(offset=offset, limit=limit)
has_more = len(anchors) >= limit has_more = len(anchors) >= limit
if wants_json(request): if wants_json(request):

22
db.py
View File

@@ -759,6 +759,28 @@ async def get_all_anchors() -> list[dict]:
return results return results
async def get_anchors_paginated(offset: int = 0, limit: int = 20) -> list[dict]:
"""Get anchors with pagination, newest first."""
async with get_connection() as conn:
rows = await conn.fetch(
"SELECT * FROM anchors ORDER BY created_at DESC LIMIT $1 OFFSET $2",
limit, offset
)
results = []
for row in rows:
result = dict(row)
if result.get("first_activity_id"):
result["first_activity_id"] = str(result["first_activity_id"])
if result.get("last_activity_id"):
result["last_activity_id"] = str(result["last_activity_id"])
if result.get("created_at"):
result["created_at"] = result["created_at"].isoformat()
if result.get("confirmed_at"):
result["confirmed_at"] = result["confirmed_at"].isoformat()
results.append(result)
return results
async def update_anchor_confirmed(merkle_root: str, bitcoin_txid: str) -> bool: async def update_anchor_confirmed(merkle_root: str, bitcoin_txid: str) -> bool:
"""Mark anchor as confirmed with Bitcoin txid.""" """Mark anchor as confirmed with Bitcoin txid."""
async with get_connection() as conn: async with get_connection() as conn: