Skip to content

Conversation

@oscarlund121
Copy link
Contributor

@oscarlund121 oscarlund121 commented Sep 22, 2025

Implements project caching and refresh logic to optimize data retrieval and ensure up-to-date project information. Updates various components to support these enhancements, including the ProjectsContextProvider and CachingProjectDataSource.

Add revalidation logic to API endpoints to keep cached data in sync.

Description

  • Avoided duplicating cache in the API: projectDataSource only (no direct repository access).
  • Updated ProjectsContextProvider to fetch /api/projects once on mount and update if data has changed.
  • GitHub webhook refreshes cache and calls revalidatePath('/(authed)/projects')

Motivation and Context

Speed up load while getting new project data automatically on hcange.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Implements project caching and refresh logic to optimize data retrieval and ensure up-to-date project information. Updates various components to support these enhancements, including the `ProjectsContextProvider` and `CachingProjectDataSource`.

Add revalidation logic to API endpoints to keep cached data in sync.
Copilot AI review requested due to automatic review settings September 22, 2025 13:04
Copy link
Contributor

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

This PR implements a comprehensive project caching system to optimize data retrieval performance while ensuring data stays up-to-date. The changes shift from a props-based data passing approach to a context-based system with automatic refresh capabilities.

Key changes:

  • Implemented client-side project caching with automatic refresh logic via API endpoints
  • Added GitHub webhook integration to trigger cache invalidation and data revalidation
  • Refactored components to use React Context instead of prop drilling for project data

Reviewed Changes

Copilot reviewed 11 out of 17 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
ProjectList.tsx Converted to use React Context instead of accepting projectDataSource prop
PopulatedProjectList.tsx Removed context sync logic as projects now come directly from context
SplitView.tsx Removed projectDataSource prop passing to ProjectList component
ProjectsContextProvider.tsx Added automatic project fetching and refresh logic with visibility change detection
ProjectRepository.ts Added debug console logging for project fetching operations
CachingProjectDataSource.ts Implemented cache-first strategy with new refreshProjects method
route.ts (projects API) New API endpoint that calls refreshProjects to get latest data
route.ts (GitHub hooks) Added project cache refresh and path revalidation on webhook events
route.ts (blob API) Added revalidation and improved caching logic for blob responses
layout.tsx Switched from projectRepository to projectDataSource for initial project loading
docker-compose.yaml Added PostgreSQL service and app service configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

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

Copilot reviewed 10 out of 17 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

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

Copilot reviewed 10 out of 17 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

removed revalidatePath from blob
Copy link
Contributor

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

Copilot reviewed 10 out of 17 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Enhances caching mechanisms in API responses by introducing revalidation and refining cache-control headers for better performance.

Adds a loading state in the ProjectsContextProvider to prevent redundant fetch calls and ensures error handling logs are more descriptive.

Simplifies code style by removing semicolons and adjusts default state initialization to optimize user experience.
Copy link
Contributor

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

Copilot reviewed 10 out of 17 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

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

Copilot reviewed 10 out of 17 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

oscarlund121 and others added 3 commits September 29, 2025 13:24
Changes the HTTP method from GET to POST for the projects API fetch request. This adjustment may address API requirements or enhance compatibility with server-side logic.
while project cache is refreshed
Eliminates the `isLoadingRef` as it was no longer in use and comments out the `hasProjectChanged` function to simplify the code.

Improves the project refresh mechanism by directly updating the state when new projects are fetched, removing unnecessary checks and reducing complexity. This enhances maintainability and ensures clearer logic flow.
Copy link
Contributor

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

Copilot reviewed 14 out of 21 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Updates the `GET /api/projects` endpoint to handle a `refresh` query parameter, enabling conditional fetching of refreshed projects.

Replaces the `GET /api/refreshedProjects` endpoint with a `POST` method that directly triggers a refresh operation.

Adjusts the `ProjectsContextProvider` to utilize the new `POST /api/refreshedProjects` endpoint, aligning with the updated API design.

Simplifies API behavior and improves clarity between fetching current vs. refreshed project data.

Refactors project API endpoints for improved refresh logic

Updates project-related API endpoints to simplify behavior and enhance clarity:

- Deprecates the `GET /api/projects` endpoint, replacing it with a `POST /api/refreshedProjects` endpoint for triggering project refresh operations.
- Modifies `ProjectsContextProvider` to utilize the new API endpoint, ensuring consistency with the updated design.
- Adds a loading guard to prevent duplicate refresh requests.

Improves maintainability and aligns API operations with the intended logic for fetching refreshed project data.
Copy link
Contributor

@ulrikandersen ulrikandersen left a comment

Choose a reason for hiding this comment

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

We're getting there! 🚀

Consolidates project data handling by improving caching logic and
removing unused API routes. Updates API endpoint paths for better
consistency. Simplifies error handling and streamlines blob retrieval
in the GET route. Enhances readability and reliability by refining
conditional checks and eliminating redundant code.
Updates error handling to treat decode failures as missing cache
instead of logging or propagating errors. This ensures robustness
when decoding cached data and prevents unintended application
breakdowns due to invalid cache contents.
Eliminates the unused setProjects function from the ProjectsContext
to simplify the context structure and remove unnecessary code.
This enhances maintainability and reduces potential confusion.

Removes unused setProjects function from context

Simplifies the ProjectsContext by removing the unused setProjects function. This improves maintainability, reduces potential confusion, and eliminates unnecessary code.

Adds a warning log to ProjectRepository for better debugging when cached project decoding fails.
Copy link
Contributor

@ulrikandersen ulrikandersen left a comment

Choose a reason for hiding this comment

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

This is super awesome! Let's get it on staging 🚀🚀🚀

@ulrikandersen ulrikandersen merged commit 3570836 into develop Sep 30, 2025
8 checks passed
@ulrikandersen ulrikandersen deleted the optimize-project-doc-loadtime branch September 30, 2025 12:59
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.

2 participants