diff --git a/app/routers/anchors.py b/app/routers/anchors.py index 3416b40..6bfb6a5 100644 --- a/app/routers/anchors.py +++ b/app/routers/anchors.py @@ -36,7 +36,7 @@ async def list_anchors( from fastapi.responses import RedirectResponse 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 if wants_json(request): diff --git a/db.py b/db.py index 3bff73c..8dd805f 100644 --- a/db.py +++ b/db.py @@ -759,6 +759,28 @@ async def get_all_anchors() -> list[dict]: 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: """Mark anchor as confirmed with Bitcoin txid.""" async with get_connection() as conn: