refactor(admin): make the activity keyset clause unconditional

_page_after decided whether to append " AND " or " WHERE " by looking for
"WHERE" in the SQL it had just been handed, which only worked because no
union branch contains one. The query builder now always emits a WHERE, so
adding a branch with its own predicate cannot silently break the cursor.
This commit is contained in:
arc53-machine committed 2026-09-22 10:43:40 +01:00
1 parent 96a930c265
commit 350caf6ace
1 file changed
+4 -3
+4 -3
View File
@@ -203,7 +203,9 @@ class ActivityRepository:
"OR COALESCE(outcome, '') ILIKE :search OR detail::text ILIKE :search)"
)
params["search"] = f"%{search}%"
where = ("WHERE " + " AND ".join(clauses)) if clauses else ""
# Always a WHERE, even with no filters, so the keyset cursor below can
# append " AND ..." without sniffing the string it was handed.
where = "WHERE " + " AND ".join(clauses or ["TRUE"])
return f"SELECT * FROM ({union}) AS activity {where}", params
def list(
@@ -269,8 +271,7 @@ class ActivityRepository:
if not sql:
return []
if cursor is not None:
sql += " AND " if "WHERE" in sql else " WHERE "
sql += "(created_at, feed, id) < (:cur_at, :cur_feed, :cur_id)"
sql += " AND (created_at, feed, id) < (:cur_at, :cur_feed, :cur_id)"
params.update(
{"cur_at": cursor[0], "cur_feed": cursor[1], "cur_id": cursor[2]}
)