From 46374d14c98f8d4dd32656557de3c364a3e5cd93 Mon Sep 17 00:00:00 2001 From: codecrafted1 Date: Sun, 28 Jun 2026 16:49:35 +0530 Subject: [PATCH 1/2] fix: use paginated repository fetch in repo explorer --- src/app/api/metrics/repo-explorer/route.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/app/api/metrics/repo-explorer/route.ts b/src/app/api/metrics/repo-explorer/route.ts index 31c34f1b1..5d9da2c5f 100644 --- a/src/app/api/metrics/repo-explorer/route.ts +++ b/src/app/api/metrics/repo-explorer/route.ts @@ -3,6 +3,7 @@ import { NextRequest } from "next/server"; import { authOptions } from "@/lib/auth"; import { isMetricsCacheBypassed, metricsCacheKey, withMetricsCache } from "@/lib/metrics-cache"; import { ExplorerRepoCardData } from "@/lib/repoAnalytics"; +import { fetchUserRepos } from "@/lib/github"; export const dynamic = "force-dynamic"; const GITHUB_API = "https://api.github.com"; @@ -16,16 +17,11 @@ export async function GET(req: NextRequest) { const bypass = isMetricsCacheBypassed(req); const key = metricsCacheKey(session.githubId ?? session.githubLogin, "repo-explorer-v2" as any, { days: 7 }); - try { - const data = await withMetricsCache({ bypass, key, ttlSeconds: 30 * 60 }, async () => { - // 1. Fetch user repos (up to 100 to show more repos) - const reposRes = await fetch(`${GITHUB_API}/user/repos?sort=pushed&per_page=100`, { - headers: { Authorization: `Bearer ${session.accessToken}`, Accept: "application/vnd.github+json" }, - cache: "no-store", - }); - - if (!reposRes.ok) throw new Error("API error fetching repos"); - const repos = await reposRes.json(); + try { + const data = await withMetricsCache( + { bypass, key, ttlSeconds: 30 * 60 }, + async () => { + const repos = await fetchUserRepos(session.accessToken); // 2. Fetch last 30 days of commits across all repos for the user const since = new Date(); @@ -94,7 +90,8 @@ export async function GET(req: NextRequest) { result.sort((a, b) => b.commitCount - a.commitCount || new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()); return { repos: result }; - }); + } + ); return Response.json(data); } catch (error) { console.error(error); From 4706da5906289d73f7ca851d6a94315eaab44eae Mon Sep 17 00:00:00 2001 From: codecrafted1 Date: Thu, 2 Jul 2026 00:25:42 +0530 Subject: [PATCH 2/2] fix: resolve review issues in repo explorer pagination --- src/app/api/metrics/repo-explorer/route.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/app/api/metrics/repo-explorer/route.ts b/src/app/api/metrics/repo-explorer/route.ts index 6fb1bd120..276b0b19f 100644 --- a/src/app/api/metrics/repo-explorer/route.ts +++ b/src/app/api/metrics/repo-explorer/route.ts @@ -1,7 +1,6 @@ import { getSessionWithToken } from "@/lib/get-session-token"; import { NextRequest } from "next/server"; import { isMetricsCacheBypassed, metricsCacheKey, withMetricsCache } from "@/lib/metrics-cache"; -import { ExplorerRepoCardData } from "@/lib/repoAnalytics"; import { fetchUserRepos } from "@/lib/github"; import { ExplorerRepoCardData } from "@/lib/repo-analytics-types"; @@ -28,15 +27,7 @@ export async function GET(req: NextRequest) { async () => { const repos = await fetchUserRepos(session.accessToken); - try { - const data = await withMetricsCache({ bypass, key, ttlSeconds: 30 * 60 }, async () => { - const reposRes = await fetch(`${GITHUB_API}/user/repos?sort=pushed&per_page=100`, { - headers: { Authorization: `Bearer ${accessToken}`, Accept: "application/vnd.github+json" }, - cache: "no-store", - }); - - if (!reposRes.ok) throw new Error("API error fetching repos"); - const repos = await reposRes.json(); + const since = new Date(); since.setDate(since.getDate() - 30); @@ -110,4 +101,4 @@ export async function GET(req: NextRequest) { console.error(error); return Response.json({ error: "GitHub API error" }, { status: 502 }); } -} \ No newline at end of file +}