Skip to content

perf(reports): split the completed-docs query (#1997) - #2308

Open
alfonsodg wants to merge 1 commit into
OpenSignLabs:stagingfrom
alfonsodg:pr/1997-completed-report
Open

alfonsodg wants to merge 1 commit into
OpenSignLabs:stagingfrom
alfonsodg:pr/1997-completed-report

Conversation

@alfonsodg

Copy link
Copy Markdown

Problem

The "Completed" tab became slow as the number of completed documents grew. The
query combined a direct CreatedBy predicate with a Signers $inQuery in a
single $or, which MongoDB cannot serve from a single index, so it fell back
to collection scans. It also populated the tenant relation, which the completed
report does not use.

Affected files

  • apps/OpenSignServer/cloud/parsefunction/getReport.js

Fix

  • The completed report runs the two predicates as two separate, index-friendly
    queries and merges the results.
  • The tenant relation is only populated for the reports that need it.

Acceptance criteria

  • The completed report uses the dedicated partial indexes
  • The result set and the ordering are unchanged

Fixes OpenSignLabs#1997

Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 22:40
@vercel

vercel Bot commented Oct 21, 2026

Copy link
Copy Markdown

@alfonsodg is attempting to deploy a commit to the prafull 's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Deep pagination loses results, the Owner column loses populated data, and searched reports bypass the optimization.

3 open issues
What changed in this PR

This PR aims to speed up the Completed report by separating creator and signer queries and reducing populated relations.

Changes:

  • Runs creator and signer queries concurrently, then deduplicates, sorts, and paginates their combined results.
  • Omits the tenant relation from Completed report includes while retaining existing includes for other reports.
File Description
apps/​OpenSignServer/​cloud/​parsefunction/​getReport.js Adds split-query handling and conditional relation includes for Completed reports.

Review effort: Balanced

const include = 'AuditTrail.UserPtr,Placeholders.signerPtr,ExtUserPtr.TenantId';
const isCompletedReport = reportId === 'kQUoW4hUXz';
const include = isCompletedReport
? 'AuditTrail.UserPtr,Placeholders.signerPtr'
Comment on lines +96 to +97
if (isCompletedReport && paramsObj && paramsObj.$or) {
const { $or, ...baseWhere } = paramsObj;
keys: json.keys || [],
orderBy,
skip: 0,
limit: Number(limit) + Number(skip) || 100,
@alfonsodg alfonsodg changed the title perf(reports): split the completed-documents query and trim the includes (#1997) perf(reports): split the completed-docs query (#1997) Oct 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants