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

fix caching of github api, only fetch 300 commits #16

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading