From b54c1b26dc01e5502a8f3c02a035d69f9d91e08f Mon Sep 17 00:00:00 2001 From: Erik Taubeneck <erik.taubeneck@gmail.com> Date: Thu, 25 Apr 2024 13:10:19 -0700 Subject: [PATCH 1/2] fix caching of github api, only fetch 300 commits --- server/app/query/create/page.tsx | 4 ++-- server/app/query/github.tsx | 12 +++++++++--- server/next.config.js | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/app/query/create/page.tsx b/server/app/query/create/page.tsx index e1c7a12..af7d32a 100644 --- a/server/app/query/create/page.tsx +++ b/server/app/query/create/page.tsx @@ -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); @@ -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); }; diff --git a/server/app/query/github.tsx b/server/app/query/github.tsx index f0b0232..665ab9c 100644 --- a/server/app/query/github.tsx +++ b/server/app/query/github.tsx @@ -31,7 +31,7 @@ export async function Branches( request: { cache: bypassCache ? "reload" : "default", }, - timestamp: new Date().getTime(), + timestamp: bypassCache ? new Date().getTime() : "", }; const branchesIter = octokit.paginate.iterator( octokit.rest.repos.listBranches, @@ -56,7 +56,7 @@ export async function Branches( request: { cache: bypassCache ? "reload" : "default", }, - timestamp: new Date().getTime(), + timestamp: bypassCache ? new Date().getTime() : "", }; const pullRequestsIter = octokit.paginate.iterator( @@ -86,6 +86,7 @@ export async function Commits( owner: string, repo: string, bypassCache: boolean, + maxCommits: number, ): Promise<string[]> { const requestParams: any = { owner: owner, @@ -94,7 +95,7 @@ export async function Commits( request: { cache: bypassCache ? "reload" : "default", }, - timestamp: new Date().getTime(), + timestamp: bypassCache ? new Date().getTime() : "", }; const commitsIter = octokit.paginate.iterator( octokit.rest.repos.listCommits, @@ -102,10 +103,15 @@ export async function Commits( ); 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; } diff --git a/server/next.config.js b/server/next.config.js index 767719f..11d5cf7 100644 --- a/server/next.config.js +++ b/server/next.config.js @@ -1,4 +1,10 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = { + logging: { + fetches: { + fullUrl: true, + }, + }, +} module.exports = nextConfig From 97089a362f422f4cb739fb9973834cf6bfc89f61 Mon Sep 17 00:00:00 2001 From: Erik Taubeneck <erik.taubeneck@gmail.com> Date: Thu, 25 Apr 2024 14:51:03 -0700 Subject: [PATCH 2/2] use string consistently for timestamps --- server/app/query/github.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/app/query/github.tsx b/server/app/query/github.tsx index 665ab9c..17177e2 100644 --- a/server/app/query/github.tsx +++ b/server/app/query/github.tsx @@ -31,7 +31,7 @@ export async function Branches( request: { cache: bypassCache ? "reload" : "default", }, - timestamp: bypassCache ? new Date().getTime() : "", + timestamp: bypassCache ? new Date().getTime().toString() : "", }; const branchesIter = octokit.paginate.iterator( octokit.rest.repos.listBranches, @@ -56,7 +56,7 @@ export async function Branches( request: { cache: bypassCache ? "reload" : "default", }, - timestamp: bypassCache ? new Date().getTime() : "", + timestamp: bypassCache ? new Date().getTime().toString() : "", }; const pullRequestsIter = octokit.paginate.iterator( @@ -95,7 +95,7 @@ export async function Commits( request: { cache: bypassCache ? "reload" : "default", }, - timestamp: bypassCache ? new Date().getTime() : "", + timestamp: bypassCache ? new Date().getTime().toString() : "", }; const commitsIter = octokit.paginate.iterator( octokit.rest.repos.listCommits,