Skip to content

perf: improve getTotalBookingDuration query#27383

Merged
Udit-takkar merged 13 commits intomainfrom
perf/yearly-duration-limit
Feb 24, 2026
Merged

perf: improve getTotalBookingDuration query#27383
Udit-takkar merged 13 commits intomainfrom
perf/yearly-duration-limit

Conversation

@Udit-takkar
Copy link
Contributor

@Udit-takkar Udit-takkar commented Jan 29, 2026

What does this PR do?

This PR fixes N+1 query in getTotalBookingDuration function.

Set this "Limit total booking duration" option with Per year

Screenshot 2026-01-29 at 4 47 45 PM

Before:-

This query was executed for n+1 times.

 Aggregate  (cost=8.18..8.19 rows=1 width=8) (actual time=0.028..0.032 rows=1 loops=1)
   Buffers: shared hit=1
   ->  Index Scan using "Booking_eventTypeId_status_idx" on "Booking"  (cost=0.14..8.17 rows=1 width=16) (actual time=0.014..0.014 rows=0 loops=1)
         Index Cond: (("eventTypeId" = 52) AND (status = 'accepted'::"BookingStatus"))
         Filter: (("startTime" >= '2026-01-01 00:00:00'::timestamp without time zone) AND ("endTime" <= '2026-12-31 23:59:59.999'::timestamp without time zone))
         Buffers: shared hit=1
 Planning:
   Buffers: shared hit=409
 Planning Time: 3.336 ms
 Execution Time: 0.129 ms
(10 rows)

After:-

Only single query per year needed now, and it is reused for all users (no per‑user query).

Updates since last revision

  • Fixed test isolation issue in durationLimits.integration-test.ts: replaced direct process.env deletion with vi.stubEnv() for automatic restoration after tests (issue identified by Cubic AI, confidence 9/10)

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • N/A I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?


Open with Devin

Link to Devin run: https://app.devin.ai/sessions/a2ba9c6b40db40c9be060ce18c6eaa94

…uration pre-fetching

Co-Authored-By: udit@cal.com <udit222001@gmail.com>
@Udit-takkar Udit-takkar marked this pull request as ready for review January 29, 2026 16:53
@Udit-takkar Udit-takkar requested a review from a team as a code owner January 29, 2026 16:53
@graphite-app graphite-app bot added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Jan 29, 2026
@graphite-app graphite-app bot requested a review from a team January 29, 2026 16:53
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

devin-ai-integration[bot]

This comment was marked as resolved.

Copy link
Member

@hariombalhara hariombalhara left a comment

Choose a reason for hiding this comment

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

Need confirmation whether there is a bug fix as well here

@github-actions github-actions bot marked this pull request as draft February 3, 2026 05:15
@pull-request-size pull-request-size bot added size/XL and removed size/L labels Feb 5, 2026
@Udit-takkar Udit-takkar marked this pull request as ready for review February 5, 2026 08:34
@Udit-takkar Udit-takkar dismissed hariombalhara’s stale review February 5, 2026 08:35

added integration test with fix

cubic-dev-ai[bot]

This comment was marked as resolved.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

Devin AI is addressing Cubic AI's review feedback

A Devin session has been created to address the issues identified by Cubic AI.

View Devin Session

…st isolation

Replace direct deletion of process.env variables with vi.stubEnv() to ensure
automatic restoration after tests, preventing flaky tests and side effects
in parallel execution.

Issue identified by Cubic AI (confidence: 9/10)

Co-Authored-By: unknown <>
Copy link
Member

@hariombalhara hariombalhara left a comment

Choose a reason for hiding this comment

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

https://app.graphite.com/github/pr/calcom/cal.com/27383/perf-improve-getTotalBookingDuration-query#comment-PRRC_kwDOFOISeM6l1CU3

I think we should add this warning because the code which prefetches and code that reads the prefetched data, it is good to have a warning

@github-actions
Copy link
Contributor

Devin AI is resolving merge conflicts

This PR has merge conflicts with the main branch. A Devin session has been created to automatically resolve them.

View Devin Session

Devin will:

  1. Merge the latest main into this branch
  2. Resolve any conflicts intelligently
  3. Run lint/type checks to ensure validity
  4. Push the resolved changes

If you prefer to resolve conflicts manually, you can close the Devin session and handle it yourself.

@Udit-takkar Udit-takkar merged commit f883dee into main Feb 24, 2026
48 checks passed
@Udit-takkar Udit-takkar deleted the perf/yearly-duration-limit branch February 24, 2026 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO ready-for-e2e size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants