Skip to content

Conversation

emrysal
Copy link
Contributor

@emrysal emrysal commented Jul 18, 2025

What does this PR do?

Remove overhead of database call for an estimated majority of runs by fixing a truthy value to become falsy, preventing additional logic from executing

@emrysal emrysal requested a review from a team as a code owner July 18, 2025 11:46
Copy link
Contributor

coderabbitai bot commented Jul 18, 2025

Walkthrough

The changes introduce additional validation when parsing the bookingLimits and durationLimits properties from the eventType object in both the _getUserAvailability function and the calculateHostsAndAvailabilities method of the AvailableSlotsService class. The new logic checks that these properties exist, are objects, and contain at least one key before attempting to parse them; otherwise, they are set to null. Additionally, two debug logging statements were removed from the _getAvailableSlots method. No changes were made to the signatures of exported or public entities.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/lib/getUserAvailability.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-playwright".

(The package "eslint-plugin-playwright" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-playwright@latest --save-dev

The plugin "eslint-plugin-playwright" was referenced from the config file in ".eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/trpc/server/routers/viewer/slots/util.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-playwright".

(The package "eslint-plugin-playwright" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-playwright@latest --save-dev

The plugin "eslint-plugin-playwright" was referenced from the config file in ".eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05e1ad0 and b4300f6.

📒 Files selected for processing (2)
  • packages/lib/getUserAvailability.ts (1 hunks)
  • packages/trpc/server/routers/viewer/slots/util.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
packages/lib/getUserAvailability.ts (2)
Learnt from: alishaz-polymath
PR: calcom/cal.com#22304
File: packages/features/eventtypes/components/MultiplePrivateLinksController.tsx:92-94
Timestamp: 2025-07-16T06:42:27.001Z
Learning: In the MultiplePrivateLinksController component (packages/features/eventtypes/components/MultiplePrivateLinksController.tsx), the `currentLink.maxUsageCount ?? 1` fallback in the openSettingsDialog function is intentional. Missing maxUsageCount values indicate old/legacy private links that existed before the expiration feature was added, and they should default to single-use behavior (1) for backward compatibility.
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.341Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.
packages/trpc/server/routers/viewer/slots/util.ts (2)
Learnt from: alishaz-polymath
PR: calcom/cal.com#22304
File: packages/features/eventtypes/components/MultiplePrivateLinksController.tsx:92-94
Timestamp: 2025-07-16T06:42:27.001Z
Learning: In the MultiplePrivateLinksController component (packages/features/eventtypes/components/MultiplePrivateLinksController.tsx), the `currentLink.maxUsageCount ?? 1` fallback in the openSettingsDialog function is intentional. Missing maxUsageCount values indicate old/legacy private links that existed before the expiration feature was added, and they should default to single-use behavior (1) for backward compatibility.
Learnt from: eunjae-lee
PR: calcom/cal.com#22106
File: packages/features/insights/components/FailedBookingsByField.tsx:65-71
Timestamp: 2025-07-15T12:59:34.341Z
Learning: In the FailedBookingsByField component (packages/features/insights/components/FailedBookingsByField.tsx), although routingFormId is typed as optional in useInsightsParameters, the system automatically enforces a routing form filter, so routingFormId is always present in practice. This means the data always contains only one entry, making the single-entry destructuring approach safe.
🧬 Code Graph Analysis (2)
packages/lib/getUserAvailability.ts (2)
packages/lib/intervalLimits/isBookingLimits.ts (1)
  • parseBookingLimit (8-13)
packages/lib/intervalLimits/isDurationLimits.ts (1)
  • parseDurationLimit (8-12)
packages/trpc/server/routers/viewer/slots/util.ts (2)
packages/lib/intervalLimits/isBookingLimits.ts (1)
  • parseBookingLimit (8-13)
packages/lib/intervalLimits/isDurationLimits.ts (1)
  • parseDurationLimit (8-12)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Security Check
🔇 Additional comments (2)
packages/lib/getUserAvailability.ts (1)

348-360: LGTM! Excellent defensive validation before parsing.

The added validation logic correctly prevents unnecessary parsing calls when bookingLimits or durationLimits are empty or invalid objects. This aligns perfectly with the PR objective of improving performance by avoiding parse operations on empty objects.

The pattern is consistent:

  1. Check property existence
  2. Validate it's an object
  3. Ensure it has at least one key
  4. Only then parse, otherwise set to null

This is a good optimization that reduces function call overhead when dealing with empty limit objects.

packages/trpc/server/routers/viewer/slots/util.ts (1)

735-747: LGTM! Consistent defensive validation implementation.

The validation logic here mirrors the excellent implementation in getUserAvailability.ts, maintaining consistency across the codebase. The same defensive checks are properly applied:

  • Validates eventType?.bookingLimits and eventType?.durationLimits exist
  • Ensures they are objects with typeof checks
  • Confirms they contain at least one key with Object.keys().length > 0
  • Only parses when valid, otherwise sets to null

This consistency ensures the performance optimization is applied uniformly across all parsing locations, preventing unnecessary function calls on empty limit objects.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@keithwillcode keithwillcode added core area: core, team members only foundation labels Jul 18, 2025
@dosubot dosubot bot added the performance area: performance, page load, slow, slow endpoints, loading screen, unresponsive label Jul 18, 2025
Copy link

delve-auditor bot commented Jul 18, 2025

No security or compliance issues detected. Reviewed everything up to b4300f6.

Security Overview
  • 🔎 Scanned files: 2 changed file(s)
Detected Code Changes
Change Type Relevant files
Enhancement ► slot.ts
    Optimize slot boundary handling
► getUserAvailability.ts
    Prevent parse when object is empty for booking/duration limits
► slots.service.ts
    Consolidate slots transformation logic
Refactor ► credit-service.ts
    Update team membership checks

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

Object.keys(eventType?.durationLimits).length > 0
? parseDurationLimit(eventType?.durationLimits)
: null;

let busyTimesFromLimitsBookingsAllUsers: Awaited<ReturnType<typeof getBusyTimesForLimitChecks>> = [];

if (eventType && (bookingLimits || durationLimits)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually executed at all times, because both bookingLimits and durationLimits were parsed {} and that's truthy. This function firing when not needed adds significant overhead; Which was completely unnecessary.

Copy link

graphite-app bot commented Jul 18, 2025

Graphite Automations

"Add ready-for-e2e label" took an action on this PR • (07/18/25)

1 label was added to this PR based on Keith Williams's automation.

@emrysal emrysal enabled auto-merge (squash) July 18, 2025 17:28
@emrysal emrysal merged commit e901e8d into main Jul 18, 2025
106 of 111 checks passed
@emrysal emrysal deleted the perf/prevent-running-limits-unnecessarily branch July 18, 2025 17:32
Copy link
Contributor

E2E results are ready!

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 foundation performance area: performance, page load, slow, slow endpoints, loading screen, unresponsive ready-for-e2e
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants