Skip to content

perf(app-store): optimize location option deduplication to O(1) - #29997

Open
webdevsamran wants to merge 1 commit into
calcom:mainfrom
webdevsamran:perf/app-store-deduplicate-locations-o1
Open

perf(app-store): optimize location option deduplication to O(1)#29997
webdevsamran wants to merge 1 commit into
calcom:mainfrom
webdevsamran:perf/app-store-deduplicate-locations-o1

Conversation

@webdevsamran

Copy link
Copy Markdown

Summary

Fixes #29959

Problem

In \getLocationGroupedOptions\ (\packages/app-store/server.ts), deduplicating options per category used \�pps[groupByCategory].find((o) => o.value === option.value)\ along with array spreading inside loops. When many app credentials exist, this produces repeated (O(N)) linear scans and array allocations resulting in (O(N^2)) execution time.

Fix

  • Maintain a \seenOptionsByCategory: Record<string, Set>\ for (O(1)) membership checks.
  • Push directly into \�pps[groupByCategory]\ rather than copying the array via spread syntax.
  • Reduces worst-case deduplication complexity from (O(N^2)) to (O(N)).

In getLocationGroupedOptions, deduplicating options per category used
apps[groupByCategory].find(...) and array spreading inside loops, resulting in
O(N^2) complexity with many credentials/apps.

Use a per-category Set to perform O(1) membership checks and push directly
to the options array, reducing worst-case complexity to O(N).

Fixes calcom#29959
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @webdevsamran! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added the 🐛 bug Something isn't working label Aug 19, 2026
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 742ae5e5-b3be-49f3-9ae7-9fbc59f05cf6

📥 Commits

Reviewing files that changed from the base of the PR and between 176037d and f8725f7.

📒 Files selected for processing (1)
  • packages/app-store/server.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

getLocationGroupedOptions now tracks location option values separately for each category. It initializes category arrays and duplicate-tracking sets when needed. It skips app location options with values already present in the category. It also ensures the default location category exists before appending the default location.

Merge Risk: ⚪ Minimal · up to f8725

This PR changes location-option deduplication to use constant-time membership checks and direct array insertion, with no actionable merge-blocking risk remaining beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the app-store performance optimization and the O(1) location option deduplication change.
Description check ✅ Passed The description explains the O(N²) problem, the Set-based fix, and the expected performance improvement in the changed function.
Linked Issues check ✅ Passed The changes address issue #29959 by using per-category Sets and direct pushes while preserving location option deduplication behavior.
Out of Scope Changes check ✅ Passed The changes are limited to the requested location option deduplication performance optimization in packages/app-store/server.ts.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance: repeated .find() calls cause O(n²) when building app location options in packages/app-store/server.ts

2 participants