perf: optimize getBusyTimesForLimitChecks with batched parallel queries#27399
perf: optimize getBusyTimesForLimitChecks with batched parallel queries#27399
Conversation
…es and raw SQL Co-Authored-By: [email protected] <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…imization Co-Authored-By: [email protected] <[email protected]>
The batching (50 user chunks) and parallel execution (Promise.all) provide the main performance optimization. Using findMany instead of $queryRaw maintains the same performance characteristics while being compatible with prismock for testing. Co-Authored-By: [email protected] <[email protected]>
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/features/busyTimes/services/getBusyTimes.ts">
<violation number="1" location="packages/features/busyTimes/services/getBusyTimes.ts:368">
P1: Rule violated: **Avoid Logging Sensitive Information**
This log serializes busyTimes including `userId`, which exposes PII in logs. Avoid logging user identifiers; log only aggregate counts or remove the busyTimes payload.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Devin AI is addressing Cubic AI's review feedbackA Devin session has been created to address the issues identified by Cubic AI. |
Replace JSON.stringify(busyTimes) with count to avoid exposing userId in logs. Addresses Cubic AI review feedback (confidence 9/10). Co-Authored-By: unknown <>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/features/busyTimes/services/getBusyTimes.ts">
<violation number="1" location="packages/features/busyTimes/services/getBusyTimes.ts:368">
P1: Rule violated: **Avoid Logging Sensitive Information**
Avoid logging sensitive data: JSON.stringify(busyTimes) includes per-booking userId values, which are PII, and should not be written to logs. Log only aggregate counts or non-identifying metadata per the "Avoid Logging Sensitive Information" rule.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Paragon: tests updated2 updated tests generated for this PR. Updated Tests
DetailsUpdated Tests
|
| @@ -351,10 +466,10 @@ export class BusyTimesService { | |||
| status: BookingStatus.ACCEPTED, | |||
| // FIXME: bookings that overlap on one side will never be counted | |||
There was a problem hiding this comment.
👀 should we take care of it in this PR? or link a issue... I know it's old but since we're touching it 🙂


What does this PR do?
TODO
Not required as we already have other index and it does a index scan when i ran the query
Optimizes the
getBusyTimesForLimitChecksquery inBusyTimesServicewhich can be slow for teams/orgs with many members due to theuserId: { in: userIds }clause.Changes:
userIdsarrays into batches of 50 and runs queries in parallelThis addresses performance concerns for organizations with hundreds of team members where the original single query with a large IN clause could cause slow query planning and execution.
Link to Devin run: https://app.devin.ai/sessions/0f1730edf1a14b2184c4b9bfb9c556d4
Requested by: @Udit-takkar
Updates since last revision
JSON.stringify(busyTimes)tocount=${busyTimes.length}to avoid exposinguserIdin logs (addressed Cubic AI review feedback, confidence 9/10)Link to Devin run (Cubic fix): https://app.devin.ai/sessions/a16fb642ff984783a46e24f5e2aed4e3
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Unit tests: Run
TZ=UTC yarn test packages/features/busyTimes/services/getBusyTimes.test.tsto verify all 15 tests pass (3 existing + 12 new)Functional testing: Create a team event type with booking limits enabled and multiple team members. Verify that:
rescheduleUidexclusion)Performance testing (optional but recommended):
Checklist
Human Review Checklist
status = 'accepted'string matchesBookingStatus.ACCEPTEDenum value