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:
@@ -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):
|
||||
|
||||
22
db.py
22
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:
|
||||
|
||||
Reference in New Issue
Block a user