fix(archive): מיון תיקי-ארכיב לפי תאריך-ארכוב (server-authoritative) #217

Merged
chaim merged 1 commits from worktree-archive-sort-fix into main 2026-06-12 04:40:21 +00:00
Showing only changes of commit d4dc58fe5a - Show all commits

View File

@@ -1713,7 +1713,12 @@ async def list_cases(
where.append("archived_at IS NULL") where.append("archived_at IS NULL")
where_clause = f"WHERE {' AND '.join(where)}" if where else "" where_clause = f"WHERE {' AND '.join(where)}" if where else ""
args.append(limit) args.append(limit)
sql = f"SELECT * FROM cases {where_clause} ORDER BY updated_at DESC LIMIT ${len(args)}" # Archived list is ordered by archive date (newest-first) so the order is
# server-authoritative and the /archive page is correct on load, regardless
# of client-side sorting. NULLS LAST is defensive — the archived_only filter
# already excludes NULLs.
order_by = "archived_at DESC NULLS LAST" if archived_only else "updated_at DESC"
sql = f"SELECT * FROM cases {where_clause} ORDER BY {order_by} LIMIT ${len(args)}"
async with pool.acquire() as conn: async with pool.acquire() as conn:
rows = await conn.fetch(sql, *args) rows = await conn.fetch(sql, *args)
return [_row_to_case(r) for r in rows] return [_row_to_case(r) for r in rows]