Skip to content

perf(server): apply targeted field projections to auth, config, and holiday queries - #34

Merged
K-Laron merged 1 commit into
mainfrom
perf/server-projections
Oct 17, 2026
Merged

K-Laron merged 1 commit into
mainfrom
perf/server-projections

Conversation

@K-Laron

@K-Laron K-Laron commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Problem

Authentication checks (requireAuth, SSE sync) and configuration lookups (getUserSettings, listHolidays) were executing unprojected Mongoose queries (User.findById().lean(), Config.findOne().lean()).

  • On every authenticated HTTP request and SSE connection, the entire User document was retrieved and deserialized, including the scrypt password hash.
  • On every entry creation/update and holiday list, Config.findOne() retrieved entire user profiles and potentially large monthly signOffs records when only settings or profile.startDate were required.

Mechanism

Add targeted Mongoose field projections using .select():

  1. server/middleware/require-auth.js: .select('authTokenHash authTokenCreatedAt')
  2. server/routes/sync.routes.js: .select('authTokenHash')
  3. server/services/entry.service.js: getUserSettings queries Config.findOne({ userId }).select('settings')
  4. server/services/holiday.service.js: listHolidays queries Config.findOne({ userId }).select('profile.startDate')
  5. Updated server/middleware/require-auth.test.js with .select() mock support and explicit projection verification test.

Upstream Inspiration

Before / After Numbers

  • npm test: 125/125 tests passing (5-run median: 539.82 ms).
  • npm run build: Vite build passes in ~1.90s.
  • Auth queries: transfers only 2 fields instead of entire user record with scrypt hash.
  • Config lookups: eliminates loading unbounded signOffs dictionary on entry updates.

Risk

Very Low. Field projections match the exact fields read by callers. Verified by test suite.

…oliday queries

Inspired by pingdotgg/t3code#13704, pingdotgg/t3code#10108, pingdotgg/t3code#10341.
Project only required fields (authTokenHash, authTokenCreatedAt, settings, profile.startDate)
to eliminate deserialization overhead and avoid transferring scrypt password hashes and
large monthly signOff objects across queries.
Copilot AI balanced review requested due to automatic review settings October 17, 2026 15:29

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aa4bfd19-dee2-4db0-b7f5-1a54c0b27a7d
  • 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

Comment @coderabbitai help to get the list of available commands.

@K-Laron
K-Laron merged commit 9b7180b into main Oct 17, 2026
5 checks passed
@K-Laron
K-Laron deleted the perf/server-projections branch October 17, 2026 23:12
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