Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor app fetching and caching logic #21

Merged
merged 2 commits into from
Feb 24, 2025
Merged

Refactor app fetching and caching logic #21

merged 2 commits into from
Feb 24, 2025

Conversation

thang14
Copy link
Contributor

@thang14 thang14 commented Feb 24, 2025

This pull request introduces significant changes to the core/apps package to improve the handling and caching of app data from GitHub and subnet sources. The most important changes include the addition of caching mechanisms, modifications to the app data structures, and enhancements to the app retrieval methods.

Caching Enhancements:

  • core/apps/service.go: Added caching fields (gitHubAppCache and subnetAppCache) to the Service struct and initialized them in the New function. Implemented methods getGitHubApps, getGitHubAppByID, and getSubnetAppByID to fetch app data with caching. [1] [2] [3]

App Data Structure Modifications:

  • core/apps/types/types.go: Updated the App struct to include new fields (Description, Logo, BannerUrls, DefaultBannerIndex, Website) and changed PeerId to PeerIds (a list of strings). Modified related functions to handle these changes. [1] [2] [3] [4]
  • proto/subnet/app/app.pb.go: Updated the protobuf definition for the App struct to reflect the change from PeerId to PeerIds. [1] [2]

App Retrieval Enhancements:

  • core/apps/app_details.go: Modified the GetApp method to fetch app data from GitHub and subnet sources, and merge them. Added logic to handle the new fields in the App struct.
  • core/apps/app_list.go: Enhanced the GetApps method to fetch app data from GitHub and apply filtering criteria. Introduced a new GitHubApp struct and a helper function appMatchesFilter to support these changes.

API Adjustments:

  • internal/api/apps.go: Updated the appResult struct and the convertToAppResult function to include the new fields from the App struct. [1] [2]

Miscellaneous:

  • core/apps/app_report.go: Adjusted the reportAllRunningContainers method to handle the updated PeerIds field in the App struct.
  • Added necessary imports in various files to support the new functionality.

- Implement caching for GitHub apps and subnet apps using `go-cache`.
- Refactor `GetApp` function to use caching for subnet apps.
- Ensure the status of the container is fetched without caching.
- Update `GetApps` function to use the new caching mechanism.
- Add necessary imports and initialize caches in the `Service` struct.
- Implement caching for the `getGitHubApps` function to reduce redundant network requests.
- Update the `Service` struct to include a cache for GitHub apps.
- Modify the `getGitHubApps` function to check the cache before making a network request.
@thang14 thang14 merged commit 9ad0391 into main Feb 24, 2025
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