Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jobenjada committed Sep 28, 2024
1 parent 7b82c6e commit fb96f32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/[githubLogin]/components/profile-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PullRequestList from "./pr-list";
import ProfileInfoBar from "./profile-info";

export default async function ProfilePage({ githubLogin }: { githubLogin: string }) {
// Get & enrich the player data
// needs work, we should cache enrolled repositories and invalidate the cache on a new enrollment
const enrichedUserData = await getEnrichedGithubUserData(githubLogin);

let pointsAndRanks: Array<{
Expand All @@ -23,6 +23,7 @@ export default async function ProfilePage({ githubLogin }: { githubLogin: string

if (enrichedUserData.enrolledRepositories && enrichedUserData.playerData?.id) {
try {
// needs work, we should invalidate the cache on new point transaction for the user
const result = await getPointsAndRankPerRepository(
enrichedUserData.enrolledRepositories,
enrichedUserData.playerData.id
Expand All @@ -39,18 +40,21 @@ export default async function ProfilePage({ githubLogin }: { githubLogin: string
let globalRank = 0;
let chanceOfWinning = 0;
if (enrichedUserData.playerData?.id) {
// needs work, we should invalidate the cache on new point transaction for the user
const result = await getTotalPointsAndGlobalRank(enrichedUserData.playerData.id);
totalPoints = result.totalPoints;
globalRank = result.globalRank;
chanceOfWinning = result.likelihoodOfWinning;
}

// needs work, we should invalidate the cache on new repository activation which happens in handleActivation in repoSelector.tsx
const ossGgRepositories = await getAllRepositories();

let pullRequests = [] as TPullRequest[];

if (enrichedUserData.status.githubUserFound) {
const ossGgRepositoriesIds = ossGgRepositories.map((repo) => `${repo.owner}/${repo.name}`);
// needs work (see comment in service)
pullRequests = await getPullRequestsByGithubLogin(ossGgRepositoriesIds, githubLogin);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/github/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const fetchPullRequestsByGithubLogin = async (
return pullRequests;
};

// this doesn't make sense as is. We could invalidate the cache in new point transaction for the user.
export const getPullRequestsByGithubLogin = unstable_cache(
fetchPullRequestsByGithubLogin,
["fetchPullRequestsByGithubLogin"],
Expand Down Expand Up @@ -124,6 +125,7 @@ const fetchAllOssGgIssuesOfRepos = async (repoGithubIds: number[]): Promise<TPul
return allIssues.flat();
};

// this cahing makes sense imo so we have 60 requests / hour to the github api
export const getAllOssGgIssuesOfRepos = unstable_cache(
fetchAllOssGgIssuesOfRepos,
["fetchAllOssGgIssuesOfRepos"],
Expand Down

0 comments on commit fb96f32

Please sign in to comment.