cal.com icon indicating copy to clipboard operation
cal.com copied to clipboard

feat: to enable optimized slots

Open vijayraghav-io opened this issue 1 year ago • 15 comments

What does this PR do?

  • Fixes #16575
  • Fixes CAL-4303

For the sake of demo video, availability is adjusted to simulate busy time as per examples in issue description. It should work same even with calendar busy times.

https://www.loom.com/share/8247ea087bae4aa497c48853bb2e3f8d?sid=33a96f51-1548-43d7-9b37-815d90ecc6b8

Video with calendar busy times (as per example)

https://www.loom.com/share/a9a04ee012134f31b4a5a0dfa6b2072e?sid=a4a98b11-263d-4799-875e-fe46b45ab8bf

Mandatory Tasks (DO NOT REMOVE)

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

vijayraghav-io avatar Sep 10 '24 19:09 vijayraghav-io

@vijayraghav-io is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 10 '24 19:09 vercel[bot]

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (09/10/24)

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

"Add community label" took an action on this PR • (09/10/24)

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

"Add foundation team as reviewer" took an action on this PR • (09/12/24)

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

graphite-app[bot] avatar Sep 10 '24 19:09 graphite-app[bot]

E2E results are ready!

github-actions[bot] avatar Sep 11 '24 12:09 github-actions[bot]

Thanks for the PR @vijayraghav-io 🙌. Haven't tested it completely yet, but code wise looks good. Can you add tests to ensure this works and won't break in the future.

Thank you! @Amit91848 , sure will add tests.

vijayraghav-io avatar Sep 11 '24 15:09 vijayraghav-io

@Amit91848, added tests.

vijayraghav-io avatar Sep 12 '24 12:09 vijayraghav-io

This availability:

@CarinaWolli , handled this edge case. Also added a test case for this.

To explain the implementation - A increment is added to the slotStartTime to adjust to be Start Of the hour, if this increment exceeds the next Start of the hour, a condition is added to Not exceed the Start of the hour. This should cover all cases.

vijayraghav-io avatar Sep 12 '24 16:09 vijayraghav-io

This PR is being marked as stale due to inactivity.

github-actions[bot] avatar Oct 31 '24 00:10 github-actions[bot]

resolved merge conflicts. Gentle reminder!

vijayraghav-io avatar Nov 10 '24 05:11 vijayraghav-io

Moving to draft since there a bunch of conflicts

keithwillcode avatar Jan 08 '25 16:01 keithwillcode

@keithwillcode, resolved conflicts and all tests are passing 🙏

vijayraghav-io avatar Jan 10 '25 06:01 vijayraghav-io

Resolved merge conflicts again, tests are passing, hence making ready for review. 🙏

vijayraghav-io avatar Feb 12 '25 08:02 vijayraghav-io

@vijayraghav-io let's fix the conflicts

anikdhabal avatar Mar 11 '25 17:03 anikdhabal

@vijayraghav-io let's fix the conflicts

sure will do

vijayraghav-io avatar Mar 12 '25 05:03 vijayraghav-io

@anikdhabal , all tests are passing 🙏 removed all unrelated changes

vijayraghav-io avatar Mar 12 '25 08:03 vijayraghav-io

@anikdhabal , Gentle Reminder 🙏

vijayraghav-io avatar Mar 17 '25 06:03 vijayraghav-io

@vijayraghav-io the pr still has merge conflicts. Can you please try to fix them. Marking this draft for now.

sure, had resolved conflicts earlier, these must be latest one, will resolve and update!

vijayraghav-io avatar Jun 30 '25 04:06 vijayraghav-io

@Devanshusharma2005 , resolved merge conflicts.

vijayraghav-io avatar Jul 01 '25 07:07 vijayraghav-io

I found one issue, everything else looked good 🙏

@CarinaWolli , fixed 🙏 , also added a test case.

vijayraghav-io avatar Jul 09 '25 15:07 vijayraghav-io

still seeing an issue with slots, see my comment below

This should fix, please check my reply https://github.com/calcom/cal.com/pull/16579#discussion_r2200598196

vijayraghav-io avatar Jul 14 '25 08:07 vijayraghav-io

This is working great now. Thanks for applying my feedback so quickly 🙏 It still needs review from @calcom/platform @calcom/dba. In the meantime, can you look into fixing the merge conflicts?

Thank you! for confirming 🙏 , sure will fix the merge conflicts.

vijayraghav-io avatar Jul 14 '25 12:07 vijayraghav-io

Walkthrough

Adds an end-to-end "showOptimizedSlots" feature: database migration and Prisma schema field, repository selects, default values and test builders, threading the flag into server slot retrieval, extending getSlots/buildSlots signatures with a new helper to adjust initial slot start times, unit tests validating optimized-slot behavior, a UI toggle and English localization entries.

Assessment against linked issues

Objective Addressed Explanation
Add a setting to enable optimized schedules; generate optimal slots while prioritizing clean start times when possible [#16575, CAL-4303]

Out-of-scope changes

Code Change Explanation
Add NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL to globalEnv (turbo.json) This CI/env declaration is unrelated to the optimized schedules feature; no objective referenced environment/global tooling changes.

Possibly related PRs

  • calcom/cal.com#22787 — touches the same available-slots retrieval flow (packages/trpc/server/routers/viewer/slots/util.ts) where showOptimizedSlots is now passed into getSlots, indicating a code-level overlap.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 00918d6ef2cb1ac863f383db841d1e6a3e12e587 and 12b8c0c0e08671a5f1b1bc4f788f8180c8c8e289.

📒 Files selected for processing (2)
  • packages/lib/slots.ts (6 hunks)
  • turbo.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • turbo.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/lib/slots.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Install dependencies / Yarn install & cache
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

coderabbitai[bot] avatar Jul 16 '25 06:07 coderabbitai[bot]

No security or compliance issues detected. Reviewed everything up to 7accaf7d0174aacc2e7cbd7fe07998c2bc388b02.

Security Overview
  • 🔎 Scanned files: 16 changed file(s)
Detected Code Changes

The diff is too large to display a summary of code changes.

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.

delve-auditor[bot] avatar Jul 22 '25 14:07 delve-auditor[bot]

Great pr @vijayraghav-io . Can you please address the typecheck issue failing.

Thank you! 🙏 , sure will address.

vijayraghav-io avatar Jul 29 '25 09:07 vijayraghav-io

@Devanshusharma2005 all checks are passing

vijayraghav-io avatar Jul 29 '25 12:07 vijayraghav-io

@emrysal for review, it's looking good from my side 🙏

CarinaWolli avatar Aug 12 '25 08:08 CarinaWolli

Reminding.....

vijayraghav-io avatar Aug 21 '25 05:08 vijayraghav-io

/tip 100 @vijayraghav-io

keithwillcode avatar Aug 27 '25 12:08 keithwillcode

🎉🎈 @vijayraghav-io has been awarded $100 by Cal.com, Inc.! 🎈🎊

algora-pbc[bot] avatar Aug 27 '25 12:08 algora-pbc[bot]

resolved merge conflicts

vijayraghav-io avatar Aug 27 '25 13:08 vijayraghav-io

Thanks @vijayraghav-io. @emrysal is currently reviewing/testing.

keithwillcode avatar Aug 27 '25 15:08 keithwillcode