Skip to content

Optimize frontend data fetching with parallelization#274

Merged
masa10-f merged 4 commits intomainfrom
feat/frontend-parallel-fetch-optimization
Feb 15, 2026
Merged

Optimize frontend data fetching with parallelization#274
masa10-f merged 4 commits intomainfrom
feat/frontend-parallel-fetch-optimization

Conversation

@masa10-f
Copy link
Owner

PR Title

Optimize frontend data fetching with parallelization

Summary

Improve frontend UX/performance by parallelizing multiple independent data fetches and reducing sequential bottlenecks in UI workflows.

Background

The user asked to continue frontend UX optimization for data retrieval and overall perceived responsiveness.

Changes

  • apps/web/src/app/scheduling/page.tsx

    • Parallelize initial load: fetch projects and schedule options in parallel.
    • Parallelize all-tasks source loading: fetch per-project tasks in parallel with Promise.allSettled.
    • Fetch quick tasks in parallel with project task fetches; log per-project failures while continuing partial success.
  • apps/web/src/app/ai-planning/page.tsx

    • Add preloadAiPlanningData and preload weekly schedules + recurring tasks when API key is already validated.
    • Use Promise.allSettled to allow partial success and avoid blocking UI.
  • apps/web/src/app/settings/page.tsx

    • Add shared getAuthContext() helper using Promise.all for supabase.auth.getUser() + supabase.auth.getSession().
    • Replace repeated sequential auth lookups in multiple handlers with the shared parallel helper.
  • apps/web/src/components/runner/manual-task-select-dialog.tsx

    • Improve resilience/perf for "all projects" mode by switching to Promise.allSettled.
    • Continue showing tasks from successfully-loaded projects even if one project fails.
  • apps/web/src/hooks/use-runner.ts

    • Reuse React Query cache for goal/project details when resolving current session's task context.
  • apps/web/src/hooks/use-project-page-state.ts

    • Run progress query keyed by projectId directly (enabled when projectId exists).

Technical Notes

  • No API contracts changed.
  • Behavior for error handling is improved to be more resilient (partial failure tolerance) while preserving existing UX.
  • Added/updated structured logging for failed sub-requests in partial-fetch flows.

Testing

  • pnpm --filter web type-check (pass)
  • Confirmed commit created on branch: feat/frontend-parallel-fetch-optimization

Commit

  • 68a97f0 Optimize frontend data fetching with parallelization

PR Checklist

  • I have verified the changes compile (type-check passed)
  • I manually reviewed affected pages/components for expected loading behavior
  • I added/updated tests where applicable
  • I have described any known limitations or follow-up tasks

Notes

  • Commit creation succeeded; pre-commit hooks may need local env write permissions.
  • git push / gh pr create currently failed in this environment due to GitHub network/DNS restrictions.

Copilot AI review requested due to automatic review settings February 15, 2026 01:55
@vercel
Copy link

vercel bot commented Feb 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
human-compiler Ready Ready Preview, Comment Feb 15, 2026 2:12am

@masa10-f masa10-f self-assigned this Feb 15, 2026
@masa10-f masa10-f added the enhancement New feature or request label Feb 15, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Optimizes frontend perceived performance and resilience by parallelizing multiple independent data fetches and tolerating partial failures (via Promise.allSettled) across scheduling, runner, AI planning, and settings flows.

Changes:

  • Parallelizes multi-source task loading (per-project + quick tasks) and continues on partial failures with structured logging.
  • Preloads AI Planning data when an API key is already validated, using partial-failure tolerant loading.
  • Reuses React Query cache for goal/project lookups in Runner session context, and parallelizes Supabase auth context reads in Settings.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
apps/web/src/hooks/use-runner.ts Reuses React Query cache for goal/project details before falling back to API calls.
apps/web/src/hooks/use-project-page-state.ts Enables project progress query based on projectId directly.
apps/web/src/components/runner/manual-task-select-dialog.tsx Fetches tasks across all projects using Promise.allSettled and logs per-project failures.
apps/web/src/app/settings/page.tsx Adds shared getAuthContext() to fetch user+session in parallel and reuses it across handlers.
apps/web/src/app/scheduling/page.tsx Parallelizes all-project tasks and quick tasks loading; continues with partial results when some fetches fail.
apps/web/src/app/ai-planning/page.tsx Adds preloadAiPlanningData to prefetch schedules + recurring tasks after API key validation using allSettled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +236 to +243
projectTaskResults.forEach((result, index) => {
if (result.status === 'fulfilled') {
allTasks.push(...(result.value as TaskInfo[]));
} else {
logger.error(
`Failed to load tasks for project ${projects[index]?.id}`,
result.reason instanceof Error ? result.reason : new Error(String(result.reason))
);
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

The per-project failure log uses projects[index]?.id, which can become inaccurate if the projects state changes between starting the requests and handling the settled results. Capture the project id alongside each promise (or close over project.id) and use that captured id for error logs to ensure correct attribution.

Copilot uses AI. Check for mistakes.
Comment on lines 69 to +82
const taskPromises = projects.map((project) =>
tasksApi.getByProject(project.id, 0, 100)
);
const taskResults = await Promise.all(taskPromises);
return taskResults.flat();
const taskResults = await Promise.allSettled(taskPromises);
return taskResults.flatMap((result, index) => {
if (result.status === 'fulfilled') {
return result.value;
}

log.error(
`Failed to load tasks for project ${projects[index]?.id}`,
result.reason instanceof Error ? result.reason : new Error(String(result.reason)),
{ component: 'ManualTaskSelectDialog' }
);
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

In the all projects fetch, the error log uses projects[index]?.id. If the projects list changes while the query is in-flight, this can log the wrong project id. Consider capturing { projectId, promise } (or closing over project.id) so the log always references the project tied to that request.

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68a97f0c27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +73 to +75
const [{ data: { user } }, { data: { session } }] = await Promise.all([
supabase.auth.getUser(),
supabase.auth.getSession(),

Choose a reason for hiding this comment

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

P1 Badge Avoid parallel auth calls in getAuthContext

Running supabase.auth.getUser() and supabase.auth.getSession() concurrently can produce an inconsistent auth snapshot when a token refresh is in flight (common after access-token expiry): getSession() may return a stale/empty session while getUser() succeeds, causing the repeated !session?.access_token checks in this page to redirect valid users to /login. Keeping these reads ordered prevents this race.

Useful? React with 👍 / 👎.

@masa10-f masa10-f merged commit 5df3699 into main Feb 15, 2026
4 checks passed
@masa10-f masa10-f deleted the feat/frontend-parallel-fetch-optimization branch February 15, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants