Skip to content

Commit

Permalink
fix caching of github api, only fetch 300 commits (#16)
Browse files Browse the repository at this point in the history
* fix caching of github api, only fetch 300 commits

* use string consistently for timestamps
  • Loading branch information
eriktaubeneck authored Apr 25, 2024
1 parent 1c0c83d commit eb3db84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions server/app/query/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function IPAForm({
setBranches(_branches);
};
const fetchCommitHashes = async () => {
const _commitHashes = await Commits(owner, repo, false);
const _commitHashes = await Commits(owner, repo, false, 300);
setCommitHashes(_commitHashes);
};
fetchBranches().catch(console.error);
Expand All @@ -192,7 +192,7 @@ function IPAForm({
const refreshBranches = async (selectedCommitHash: string) => {
const _branches = await Branches(owner, repo, true);
setBranches(_branches);
const _commitHashes = await Commits(owner, repo, true);
const _commitHashes = await Commits(owner, repo, true, 300);
setCommitHashes(_commitHashes);
};

Expand Down
12 changes: 9 additions & 3 deletions server/app/query/github.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function Branches(
request: {
cache: bypassCache ? "reload" : "default",
},
timestamp: new Date().getTime(),
timestamp: bypassCache ? new Date().getTime().toString() : "",
};
const branchesIter = octokit.paginate.iterator(
octokit.rest.repos.listBranches,
Expand All @@ -56,7 +56,7 @@ export async function Branches(
request: {
cache: bypassCache ? "reload" : "default",
},
timestamp: new Date().getTime(),
timestamp: bypassCache ? new Date().getTime().toString() : "",
};

const pullRequestsIter = octokit.paginate.iterator(
Expand Down Expand Up @@ -86,6 +86,7 @@ export async function Commits(
owner: string,
repo: string,
bypassCache: boolean,
maxCommits: number,
): Promise<string[]> {
const requestParams: any = {
owner: owner,
Expand All @@ -94,18 +95,23 @@ export async function Commits(
request: {
cache: bypassCache ? "reload" : "default",
},
timestamp: new Date().getTime(),
timestamp: bypassCache ? new Date().getTime().toString() : "",
};
const commitsIter = octokit.paginate.iterator(
octokit.rest.repos.listCommits,
requestParams,
);

let commitsArray: string[] = [];
let pages: number = 0;
for await (const { data: commits } of commitsIter) {
for (const commit of commits) {
commitsArray.push(commit.sha);
}
pages++;
if (pages * 100 > maxCommits) {
break;
}
}
return commitsArray;
}
8 changes: 7 additions & 1 deletion server/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {
logging: {
fetches: {
fullUrl: true,
},
},
}

module.exports = nextConfig

0 comments on commit eb3db84

Please sign in to comment.