Skip to content

perf(app-store): replace O(n^2) .find() with O(1) Set deduplication in getLocationGroupedOptions (#29959) - #30008

Open
jihadMo wants to merge 1 commit into
calcom:mainfrom
jihadMo:perf/app-location-options-set-dedup-29959
Open

perf(app-store): replace O(n^2) .find() with O(1) Set deduplication in getLocationGroupedOptions (#29959)#30008
jihadMo wants to merge 1 commit into
calcom:mainfrom
jihadMo:perf/app-location-options-set-dedup-29959

Conversation

@jihadMo

@jihadMo jihadMo commented Aug 19, 2026

Copy link
Copy Markdown

Closes #29959

Summary of Changes

  • Replaced $O(n^2)$ repeated .find() and spread-array reallocations in getLocationGroupedOptions with an $O(1)$ seenOptionsByCategory: Record<string, Set<string>> lookup table in packages/app-store/server.ts.
  • Reduces duplicate option filtering time complexity from $O(n^2)$ to $O(n)$, drastically improving response latency and reducing server CPU overhead when accounts have dozens of installed app credentials.

Verification

  • Verified that output shape and grouping structure are identical to existing functionality while maintaining $O(1)$ per-item lookup cost.

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

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @jihadMo! 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!

@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: ca83b9a2-46a9-430c-8860-a7dbcf25efa2

📥 Commits

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

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

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


📝 Walkthrough

Walkthrough

Updated getLocationGroupedOptions to use a Set for each category. The function now checks option values through these sets before insertion. Grouping and location assembly behavior remains unchanged.

Merge Risk: ⚪ Minimal · up to 312a1

This localized change replaces repeated linear searches with Set-based deduplication while preserving the existing output structure; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the O(n²) to O(1) Set deduplication change in getLocationGroupedOptions.
Description check ✅ Passed The description directly explains the performance change, affected function, expected behavior, and verification.
Linked Issues check ✅ Passed The change satisfies issue #29959 by replacing repeated linear duplicate checks with per-category Set membership while preserving output behavior.
Out of Scope Changes check ✅ Passed The reported changes are limited to the requested performance optimization in packages/app-store/server.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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

CLAassistant commented Aug 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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/L

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