Skip to content

Optimize onboarding chat document creation with Promise.all#822

Open
ishaanxgupta wants to merge 2 commits intosupermemoryai:mainfrom
ishaanxgupta:ishaan/sidebar
Open

Optimize onboarding chat document creation with Promise.all#822
ishaanxgupta wants to merge 2 commits intosupermemoryai:mainfrom
ishaanxgupta:ishaan/sidebar

Conversation

@ishaanxgupta
Copy link
Copy Markdown
Contributor

Replaced the sequential for loop that calls $fetch for document creation with an asynchronous draftDocs.map logic resolving via Promise.all.
The setup side-bar execution was blocked by N+1 consecutive API fetch calls. Running them concurrently improves wait-time during the onboarding experience.

@entelligence-ai-pr-reviews
Copy link
Copy Markdown

entelligence-ai-pr-reviews bot commented Apr 2, 2026

EntelligenceAI PR Summary

Optimizes document creation in ChatSidebar by parallelizing async operations for improved performance.

  • Replaced for...of loop with Array.map returning promises, wrapped in Promise.all for concurrent execution
  • Replaced imperative push pattern with a type-guarded filter on resolved Promise.all results to collect valid document IDs

Confidence Score: 5/5 - Safe to Merge

Safe to merge — this PR correctly parallelizes document creation in ChatSidebar by replacing a sequential for...of loop with Promise.all over an Array.map, which is a well-established pattern for concurrent async operations. The use of a type-guarded filter to collect valid document IDs from resolved results is a cleaner and more idiomatic approach than the imperative push pattern it replaces. No logical regressions, race conditions, or error-handling gaps were identified — Promise.all semantics are appropriate here assuming a single failure is acceptable to propagate (fail-fast), which is consistent with the original sequential behavior on error. The change is a straightforward performance optimization with no observable behavioral difference under the happy path.

Key Findings:

  • Replacing sequential for...of with Promise.all over Array.map correctly parallelizes independent async document creation calls, reducing total latency from sum-of-all to max-of-all without introducing ordering dependencies.
  • The type-guarded filter on Promise.all results cleanly eliminates the mutable push pattern, producing a more declarative and less error-prone collection of valid document IDs.
  • No new issues were identified by automated review — zero critical, significant, or medium-severity findings across the changed file.
  • The fail-fast behavior of Promise.all on rejection is consistent with the original loop's error propagation, so no regression in error handling semantics is introduced.

@entelligence-ai-pr-reviews
Copy link
Copy Markdown

Walkthrough

Refactored the document creation logic in ChatSidebar to execute operations in parallel rather than sequentially. The previous for...of loop has been replaced with Promise.all combined with Array.map, and result collection now uses a type-guarded filter instead of imperative array pushing, improving performance when creating multiple documents simultaneously.

Changes

File(s) Summary
apps/web/components/onboarding/setup/chat-sidebar.tsx Replaced sequential for...of document creation loop with parallel execution using Promise.all and Array.map; replaced imperative array pushing with type-guarded filter to collect valid document IDs from resolved results.

🔗 Cross-Repository Impact Analysis

Enable automatic detection of breaking changes across your dependent repositories. → Set up now

Learn more about Cross-Repository Analysis

What It Does

  • Automatically identifies repositories that depend on this code
  • Analyzes potential breaking changes across your entire codebase
  • Provides risk assessment before merging to prevent cross-repo issues

How to Enable

  1. Visit Settings → Code Management
  2. Configure repository dependencies
  3. Future PRs will automatically include cross-repo impact analysis!

Benefits

  • 🛡️ Prevent breaking changes across repositories
  • 🔍 Catch integration issues before they reach production
  • 📊 Better visibility into your multi-repo architecture

@ishaanxgupta
Copy link
Copy Markdown
Contributor Author

@MaheshtheDev @Dhravya please have a look

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant