This query or mutation function ran multiple paginated queries. Convex only supports a single paginated query in each function.
export const fnA = query({
args: {
a: v.id("x")
},
handler: async (b, c) => {
// Fetch list
const d = await HelperA.getAll(b, c.a)
// Map totals
const e = new Map<string, number>()
for (const f of d) {
const g = await HelperB.sum(b, {
namespace: `${c.a}-${f}`
})
if (g > 0) {
e.set(f, g)
}
}
// Rolling top list
const h: Array<{
i: Id<"u">
j: Id<"p">
k: number
l: number
m: number
}> = []
// Pagination
let n: string | null = null
let o = false
while (!o) {
const p = await b.db
.query("q")
.filter((r) => r.eq(r.field("x"), c.a))
.paginate({ cursor: n, numItems: CONST_A })
// Process batch
for (const s of p.page) {
const t = e.get(s.j) || 0
if (t > 0) {
const u = (s.v / t) * 100
const w = Math.round(u * 100) / 100
const x = {
i: s.i,
j: s.j,
k: s.v,
l: t,
m: w
}
if (h.length < 10) {
h.push(x)
h.sort((y, z) => z.m - y.m)
} else {
invariant(h.length === 10, "should be 10")
invariant(h[9], "index 9 defined")
if (w > h[9].m) {
h[9] = x
h.sort((y, z) => z.m - y.m)
}
}
}
}
n = p.continueCursor
o = p.isDone
}
// Enrich results
const aa = await asyncMap(h, async (ab) => {
const [ac, ad] = await Promise.all([
b.db.get(ab.j),
b.db.get(ab.i)
])
return {
...ab,
ae: ac?.af || "Unknown A",
ag: ad?.ah || "Unknown B"
}
})
return aa
}
})