Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/backend/queries/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const getChallengeFeed = query({
const follows = await ctx.db
.query("follows")
.withIndex("followerId", (q) => q.eq("followerId", currentUser._id))
.collect();
.take(1000);
followingIds = new Set(follows.map((f) => f.followingId));

if (authDebugEnabled) {
Expand Down Expand Up @@ -256,12 +256,12 @@ export const getChallengeFeed = query({
ctx.db
.query("likes")
.withIndex("activityId", (q) => q.eq("activityId", activity._id))
.collect()
.take(500)
.then((likes) => likes.length),
ctx.db
.query("comments")
.withIndex("activityId", (q) => q.eq("activityId", activity._id))
.collect()
.take(500)
.then((comments) => comments.length),
])
: [0, 0];
Expand Down
23 changes: 23 additions & 0 deletions tasks/2026-03-01-fix-activity-pagination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Fix Activity Feed Pagination Error

**Date:** 2026-03-01
**Issue:** Sentry error #7280439142 — `getChallengeFeed` throws "multiple paginated queries" error

## Problem

The `getChallengeFeed` query uses Convex's built-in `.paginate()` for the main activity feed, but also calls `.collect()` within the hydration loop to count likes and comments per activity. Convex only allows a single paginated query per function execution; `.collect()` on larger result sets can internally trigger paginated reads, conflicting with the explicit `.paginate()` call.

**Error:** `Uncaught Error: This query or mutation function ran multiple paginated queries. Convex only supports a single paginated query in each function.`

**Stack:** `handler in ../../queries/activities.ts [Line 229]`

## Fix

- [x] Replace `.collect()` calls with bounded `.take()` reads for likes and comments counting inside the paginated hydration loop
- [x] Replace `.collect()` on the follows query with `.take()` to be defensive
- [x] Verify typecheck and lint pass

## Notes

- `.take(n)` avoids the internal pagination mechanism that `.collect()` can trigger for larger result sets
- The limits chosen (1000 for follows, 500 for likes/comments) are generous for real-world usage and stay within Convex's per-function document read limits
Loading