I have a paginated Query, using stream inside this query. In my table are 4600 entries (which are very few). I use convex selfhosted.
The paginated query failes with
Uncaught Error: Too many documents read in a single function execution (limit: 32000).
But how is that ever possible? I give you my setup. I have a table, called "report".
report: defineTable({
title: v.optional(v.string()),
content: v.string(),
content_summarized: v.string(),
}).index("title", ["title"])
As you see, I have index. But in my streamed query I can not used it, because I do a custom filter with string compare. And I do a join so that I merge another stream. Function searchReportByFilter is the one which makes troubles.
export const searchReportByFilter = query({
args: {
paginationOpts: paginationOptsValidator,
_term: v.optional(v.string()),
title: v.optional(v.string()),
},
handler: async (ctx, args) => {
// setup report stream
const reportsStream = stream(ctx.db, schema)
.query("report")
.withIndex("by_creation_time")
.order(args.sorting === "oldest" ? "asc" : "desc");
// "join" users
const reportsWithUsersStream = reportsStream.map(async report => {
const user = (await ctx.db.get(report.report_from)) || null;
return { report, user };
});
// filter by search term called _term
let reportsFiltered = reportsWithUsersStream.filterWith(async () => true);
reportsFiltered = reportsFiltered.filterWith(async ({ report }) => {
if (args._term == null || args._term.trim() === "") {
return true;
}
const searchIn = (
(report.title ?? "") +
" " +
(report.content_summarized ?? "")
).toLowerCase();
return searchIn.includes(args._term.toLowerCase());
});
// apply the pagination Options
return await reportsFiltered.paginate(args.paginationOpts);
}
});