Skip to content

perf: avoid dist queries during team read authorization - #1204

Closed
zombieJ wants to merge 2 commits into
masterfrom
codex/optimize-team-read-query
Closed

zombieJ wants to merge 2 commits into
masterfrom
codex/optimize-team-read-query

Conversation

@zombieJ

@zombieJ zombieJ commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Look up the package identity and its team binding separately. The package lookup selects only the fields needed for read authorization and avoids loading dist records.
  • Pass the resolved package ID as a parameter to the binding lookup so each table can use its own collation.
  • Keep the existing administrator and team membership checks.

Verification

  • Type check and scoped formatting and lint checks passed.
  • MySQL 9.3 with different package ID collations on the two tables. Checked bound, public, and missing packages. EXPLAIN showed indexed lookups on both tables.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 08:11
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Read-access checks now use a repository lookup that returns packages with team bindings. The separate team-binding check was removed, and forbidden-access messages build package fullnames from scope and name.

Changes: Team-bound read access

Layer / File(s) Summary
Package lookup and access check
app/repository/PackageRepository.ts, app/port/UserRoleManager.ts, app/repository/TeamRepository.ts
PackageRepository adds findTeamBoundPackage, which filters by scope and name and requires a matching TeamPackage ID. checkReadAccess uses this lookup and formats the forbidden-access fullname from scope and name. TeamRepository.hasAnyTeamBinding is removed.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Refactor

Suggested reviewers: elrrrrrrr

Merge Risk: Minimal · up to b2b18

No merge-blocking risk is identified in the supplied evidence.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title identifies the performance improvement for team read authorization. It is concise and related to the change, which combines package and team-binding lookup.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 574a16f6-0e71-47b4-98c0-8ceea0eb4c63
Commits

Reviewing files that changed from the base of the PR and between 09a9c22 and b2b18a1.

Files selected for processing: 3

  • app/port/UserRoleManager.ts
  • app/repository/PackageRepository.ts
  • app/repository/TeamRepository.ts
Files with no reviewable changes: 1

  • app/repository/TeamRepository.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T08:11:58.625125Z b2b18a1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change consolidating team-based package authorization queries.

No open issues 🎉

What changed in this PR

This PR reduces database queries for team-based package read authorization in cnpmcore while preserving administrator and team membership checks.

Changes:

  • Combine package lookup and team-binding detection into one query, selecting only fields needed for authorization.
  • Update read authorization to use the combined lookup and construct the package name for error messages.
  • Remove the separate team-binding existence query.
File Description
app/​repository/​TeamRepository.ts Remove the unused hasAnyTeamBinding method.
app/​repository/​PackageRepository.ts Add a minimal-field lookup for team-bound packages.
app/​port/​UserRoleManager.ts Use the combined lookup while retaining existing access checks.

Review effort: Balanced

@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.37%. Comparing base (4ba73c2) to head (77abd17).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1204      +/-   ##
==========================================
- Coverage   94.51%   94.37%   -0.15%     
==========================================
  Files         213      213              
  Lines        9110     9112       +2     
  Branches     1814     1814              
==========================================
- Hits         8610     8599      -11     
- Misses        500      513      +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zombieJ zombieJ changed the title perf: reduce queries for team read authorization perf: avoid dist queries during team read authorization Nov 10, 2026
@zombieJ zombieJ closed this Nov 11, 2026
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