From b1f1973df4f91ba491a1d82090b4fb88ae001ae7 Mon Sep 17 00:00:00 2001 From: sickerine Date: Sat, 28 Nov 2026 08:33:05 +0000 Subject: [PATCH 1/2] perf(screening): Papers' counts under one narrowing, and the overview's pace, read the counts kept for them Step two of two. The counts are kept since #1616, and its backfill checked clean on shared dev (migrations/screeningFacets:verify returned 0 at 08:27 UTC). At 5,000 papers with two reviewers (convex/bench/screening-team.bench.ts), each count checked against the cards and votes read whole: - tab counts under one reviewer: 10,009 documents (2.8 MB) a read to 252 (273 KB) - under one reviewer voted include: 6,676 (1.7 MB) to 92 (93 KB) - under one source: 5,009 (1.2 MB) to 162 (170 KB) - the overview's votes of the last days: 1,012 (314 KB) to 58 (58 KB) Narrowed two ways at once, Papers still counts the cards one by one. The counts are a moment behind a vote, so cards.test.ts lets their worker run before it reads them. --- convex/screening/cards.test.ts | 6 +++++- convex/screening/paperViews.ts | 22 ++++++++++++++++------ convex/screening/view.ts | 4 ++-- scripts/convex-rules.json | 1 - 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/convex/screening/cards.test.ts b/convex/screening/cards.test.ts index d258dd58e..0e76c3857 100644 --- a/convex/screening/cards.test.ts +++ b/convex/screening/cards.test.ts @@ -13,7 +13,11 @@ it("counts a source's papers and a reviewer's by where they stand, follows a pap const { jobId, papers } = await started(made, ["ann", "ben"], 3); const source = papers[0]!.sourceId!; const vote = (name: string, paperId: Id<"screeningResults">, decision: "include" | "exclude") => made.as[name]!.mutation(api.screening.voting.vote, { workspaceId, jobId, paperId, decision, ...(decision === "exclude" ? { reason: "other" } : {}) }); - const counts = (name: string, narrowed: object = {}) => made.as[name]!.query(api.screening.paperViews.counts, { workspaceId, jobId, ...narrowed }); + // Counts are kept by a worker a moment after each change (./facets.ts): it runs before each is read. + const counts = async (name: string, narrowed: object = {}) => { + await made.t.finishAllScheduledFunctions(vi.runAllTimers); + return await made.as[name]!.query(api.screening.paperViews.counts, { workspaceId, jobId, ...narrowed }); + }; expect(await counts("ann", { source })).toEqual({ include: 0, maybe: 0, exclude: 0, conflict: 0, waiting: 3 }); // The first is included by both, the second splits them, the third waits for Ben. diff --git a/convex/screening/paperViews.ts b/convex/screening/paperViews.ts index 59aca4315..b08ad4953 100644 --- a/convex/screening/paperViews.ts +++ b/convex/screening/paperViews.ts @@ -19,6 +19,7 @@ import { placeOf } from "./settling"; import { decisionValidator, paperResultValidator, paperViewValidator, voteViewValidator } from "./validators"; import { progressRow } from "./bookkeeping"; import { keepsVotes } from "./view"; +import { tallyForReason, tallyOfReviewer, tallyUnder } from "./facets"; type Paper = Doc<"screeningResults">; type Vote = Doc<"screeningVotes">; @@ -186,19 +187,28 @@ export const counts = workspaceQuery({ if (!looking) return null; const check = asked === "start" ? looking.first : asked; if (asked === "start" && !check) return null; + const row = reviewer ? [...looking.reviewers.values()].find((one) => viewId(one) === reviewer || one._id === reviewer) : undefined; + if (reviewer && !row) return null; + // Which way someone else voted is kept from a reviewer who still has papers to vote on (./view.ts `keepsVotes`): so is how many they voted each way. + const others = row && voted && voted !== "none" && voted !== "failed" && row._id !== looking.reviewer?._id; + if (others && !showsEarly(looking.job.rule!, row.kind) && keepsVotes(looking.job, looking.reviewer, (await progressRow(ctx as QueryCtx, jobId))?.reviewers, looking.reviewers.values(), (await invitationsTo(ctx, jobId)).length)) return null; + // Narrowed one way, the counts are kept already (./facets.ts): a few counted reads, whatever the screening's size. + const narrowed = [source, check, reason, row].filter(Boolean).length; + if (narrowed === 1) { + if (row) return await tallyOfReviewer(ctx, row._id, voted === "none" ? ["waiting"] : voted === "failed" ? ["failed"] : voted ? [voted] : ["include", "maybe", "exclude"]); + if (source) return await tallyUnder(ctx, jobId, { source }); + if (check) return await tallyUnder(ctx, jobId, { check }); + return await tallyForReason(ctx, jobId, reason!); + } + // Narrowed two ways at once, the papers' cards are counted one by one. ponytail: a namespace per pair of narrowings would count those too, if they come to be used on large screenings. const keeps = (card: Doc<"screeningCards">) => !card.withdrawn && (!source || card.sourceId === source) && (!check || card.checkId === check) && (!reason || (card.result === "exclude" && (card.reason ?? NO_REASON) === reason)); const tally = { include: 0, maybe: 0, exclude: 0, conflict: 0, waiting: 0 }; const cards = await ctx.db.query("screeningCards").withIndex("by_job", (q) => q.eq("jobId", jobId)).take(COUNTED + 1); if (cards.length > COUNTED) return null; - if (!reviewer) { + if (!row) { for (const card of cards) if (keeps(card)) tally[card.result]++; return tally; } - const row = [...looking.reviewers.values()].find((one) => viewId(one) === reviewer || one._id === reviewer); - if (!row) return null; - // Which way someone else voted is kept from a reviewer who still has papers to vote on (./view.ts `keepsVotes`): so is how many they voted each way. - const others = voted && voted !== "none" && voted !== "failed" && row._id !== looking.reviewer?._id; - if (others && !showsEarly(looking.job.rule!, row.kind) && keepsVotes(looking.job, looking.reviewer, (await progressRow(ctx as QueryCtx, jobId))?.reviewers, looking.reviewers.values(), (await invitationsTo(ctx, jobId)).length)) return null; const votes = ctx.db.query("screeningVotes"); const theirs = await (voted === "none" || voted === "failed" ? votes.withIndex("by_reviewer_and_status_and_place", (q) => q.eq("reviewerId", row._id).eq("status", voted === "none" ? "waiting" : "failed")) diff --git a/convex/screening/view.ts b/convex/screening/view.ts index fa437eeb3..0288e9846 100644 --- a/convex/screening/view.ts +++ b/convex/screening/view.ts @@ -25,6 +25,7 @@ import { dealable, firstCheck, inWhole, invitationsTo, laterChecks, modelName, m import { noticeOf } from "./notices"; import { NO_RESULTS } from "./settling"; import { askedWhereValidator, ruleValidator, invitedViewValidator, libraryWriteProblemValidator, retiredCriteriaValidator, unreadSourcesValidator, modelVotesValidator, checkSourcesValidator, criteriaValidator, ELSEWHERE_MAX, elsewhereValidator, everyValidator, figuresValidator, leftOutWhyValidator, PAIRS_MAX, reviewerViewsValidator, reviewerViewValidator, sourceViewsValidator, starsValidator } from "./validators"; +import { castSince } from "./facets"; const personValidator = v.object({ id: v.id("users"), name: v.string(), imageUrl: v.optional(v.string()) }); @@ -497,7 +498,6 @@ const CHANGED = new Set(["settings", "reviewerAdded", "reviewerRemoved", "madeVi /** Checks counted for a methods paragraph, saves of its settings counted, and votes counted for a person's pace. */ const CHECKS_COUNTED = 400; const CHANGES_COUNTED = 200; -const RECENT_VOTES = 500; export const figuresAction = defineUserQuery({ path: "screening/view:figures", @@ -518,7 +518,7 @@ export const figuresAction = defineUserQuery({ ]); const idOf = new Map(reviewers.map((one) => [one._id, viewId(one)])); const people = reviewers.filter((one) => one.kind === "person" && one.left === undefined && one.userId); - const recent = await Promise.all(people.map(async (one) => [viewId(one), (await ctx.db.query("screeningVotes").withIndex("by_reviewer_and_status_and_at", (q) => q.eq("reviewerId", one._id).eq("status", "cast").gte("at", since)).take(RECENT_VOTES)).length] as const)); + const recent = await Promise.all(people.map(async (one) => [viewId(one), await castSince(ctx as QueryCtx, one._id, since)] as const)); // The searches for papers its sources gained. A save that read a source it added or widened searched nothing again. const later = checks.filter((check) => check.search && check.state === "done"); return { diff --git a/scripts/convex-rules.json b/scripts/convex-rules.json index 06c011577..d025f06c3 100644 --- a/scripts/convex-rules.json +++ b/scripts/convex-rules.json @@ -124,7 +124,6 @@ "PAIRS_MAX": "the pairs of reviewers a screening's overview draws agreement for; a screening with more reviewers than that many pairs shows the first", "CHECKS_COUNTED": "a screening's checks for new papers counted for its methods paragraph: the first of them", "CHANGES_COUNTED": "a screening's latest activity, looked through for how often its settings were changed", - "RECENT_VOTES": "one person's votes of the last days, counted for their pace", "CHECK_COUNTED": "the papers one check added, looked at for where they stand; a check that added more shows no such count", "READING_LOOKED": "The rail looks at a workspace's newest open screenings for one whose models are reading: the first few, since the ring shows one." }, From b5a3e5ed5cd3f6b9b2b619aa21363928035dc858 Mon Sep 17 00:00:00 2001 From: sickerine Date: Sat, 28 Nov 2026 08:58:51 +0000 Subject: [PATCH 2/2] perf(screening): a reviewer's count of every vote they cast takes in a model's vote not yet decided As the old count did: a model's vote is cast before the bookkeeping works out its decision, and is counted under `cast` until then (#1618). --- convex/screening/paperViews.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convex/screening/paperViews.ts b/convex/screening/paperViews.ts index b08ad4953..bd29d6578 100644 --- a/convex/screening/paperViews.ts +++ b/convex/screening/paperViews.ts @@ -195,7 +195,7 @@ export const counts = workspaceQuery({ // Narrowed one way, the counts are kept already (./facets.ts): a few counted reads, whatever the screening's size. const narrowed = [source, check, reason, row].filter(Boolean).length; if (narrowed === 1) { - if (row) return await tallyOfReviewer(ctx, row._id, voted === "none" ? ["waiting"] : voted === "failed" ? ["failed"] : voted ? [voted] : ["include", "maybe", "exclude"]); + if (row) return await tallyOfReviewer(ctx, row._id, voted === "none" ? ["waiting"] : voted === "failed" ? ["failed"] : voted ? [voted] : ["include", "maybe", "exclude", "cast"]); if (source) return await tallyUnder(ctx, jobId, { source }); if (check) return await tallyUnder(ctx, jobId, { check }); return await tallyForReason(ctx, jobId, reason!);