Skip to content

Commit

Permalink
Fetch README files for user repositories
Browse files Browse the repository at this point in the history
Added functionality in `Profile.razor` to fetch README files for user repositories and update the state. Introduced a new `FetchReadmes` method in the `IUserService` interface and implemented it in `UserService.cs` to fetch README content in parallel. Removed redundant caching and fetching code in `UserService`.
  • Loading branch information
sametcn99 committed Aug 5, 2024
1 parent 8dac6b2 commit ca16a25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions GPVBlazor/GPVBlazor/Components/Pages/Profile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ else
{
stats = new RepositoryStats(repositories);
StateHasChanged();
repositories = await UserService.FetchReadmes(Username, token, repositories);
StateHasChanged();
}
}
}
Expand Down
1 change: 1 addition & 0 deletions GPVBlazor/GPVBlazor/Services/Interfaces/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface IUserService
{
Task<User?> FetchUserProfile(string username, string token);
Task<List<Repository>> FetchUserRepositories(string username, string token, int count, int page = 1);
Task<List<Repository>> FetchReadmes(string username, string token, List<Repository> repositories);
Task<UserSearchResult> SearchUsers(string inputValue);
}
}
15 changes: 9 additions & 6 deletions GPVBlazor/GPVBlazor/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ public async Task<List<Repository>> FetchUserRepositories(string username, strin
// Flatten the results
repos.AddRange(allRepos.SelectMany(r => r));

// Cache the fetched repositories
_memoryCache.Set(cacheKey, repos, TimeSpan.FromHours(1));
return repos;
}

// Fetch README content in parallel
var readmeTasks = repos
public async Task<List<Repository>> FetchReadmes(string username, string token, List<Repository> repositories)
{
var readmeTasks = repositories
.Where(repo => repo.Name != null && !string.IsNullOrEmpty(token))
.Select(async repo =>
{
Expand All @@ -123,9 +128,7 @@ public async Task<List<Repository>> FetchUserRepositories(string username, strin

await Task.WhenAll(readmeTasks);

// Cache the fetched repositories
_memoryCache.Set(cacheKey, repos, TimeSpan.FromHours(1));
return repos;
return repositories;
}

public async Task<Readme?> FetchReadmeInfo(string username, string repoName, string token)
Expand Down Expand Up @@ -154,4 +157,4 @@ public async Task<List<Repository>> FetchUserRepositories(string username, strin
return null;
}
}
}
}

0 comments on commit ca16a25

Please # to comment.