Skip to content

Implement request deduplication for redundant auth and data fetching #1188

@bdougie

Description

@bdougie

Problem

The workspace issues page makes redundant auth checks and data fetches, with the same requests happening 4-5 times in rapid succession.

User Impact:

  • Unnecessary network traffic
  • Slower perceived performance
  • Waterfall of duplicate requests

Evidence from console logs:

[LOG] [Workspace] Checking auth status...  (×2)
[DEBUG] [Auth] No authenticated user found  (×4)
[DEBUG] Fetched workspace repositories: 1 [Object]  (×4)
[DEBUG] Transformed repositories: 1 [Object]  (×4)
[LOG] Issue data last synced 38100.0 minutes ago (stale)  (×5)
[WARNING] No GitHub token available for syncing issues  (×5)

Root Cause

Multiple components fetch the same data independently without coordination:

  • No request deduplication layer
  • Each component trigger fires its own fetch
  • React Query or SWR not implemented for global state management

Proposed Solution

Implement React Query for automatic request deduplication:

// App.tsx or WorkspacePage.tsx
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 60 * 1000,         // 1 minute
      refetchOnWindowFocus: false,
      refetchOnMount: false,
      retry: 1,
    },
  },
});

export function WorkspacePage() {
  return (
    <QueryClientProvider client={queryClient}>
      {/* workspace content */}
    </QueryClientProvider>
  );
}
// hooks/useWorkspaceRepositories.ts
export function useWorkspaceRepositories(workspaceId: string) {
  return useQuery({
    queryKey: ['workspace-repos', workspaceId],
    queryFn: async () => {
      const { data } = await supabase
        .from('workspace_repositories')
        .select('*')
        .eq('workspace_id', workspaceId);
      return data;
    },
    staleTime: 5 * 60 * 1000,  // 5 minutes
  });
}

Expected Impact

  • Reduces duplicate requests by ~75%
  • Single source of truth for fetched data
  • Automatic background refetching
  • Better loading states across components
  • Cleaner data flow

Acceptance Criteria

  • Install @tanstack/react-query
  • Wrap workspace pages with QueryClientProvider
  • Convert auth checks to use React Query
  • Convert repository fetching to use React Query
  • Verify "Fetched workspace repositories" appears only once in console
  • All data still displays correctly

Dependencies

Related

See full audit: tasks/workspace-issues-performance-audit.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthooksChanges to React hooksperformancePerformance improvements and monitoringpriority-2Medium priority - depends on priority-1refactoring

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions