diff --git a/src/lib/githubYearInReview.ts b/src/lib/githubYearInReview.ts index 23c4538..60f3ccb 100644 --- a/src/lib/githubYearInReview.ts +++ b/src/lib/githubYearInReview.ts @@ -6,6 +6,17 @@ import { buildHourlyHeatmapFromCommitDates, getMostActiveDayFromCalendar, getMos import { logger } from "@/lib/logger"; + +const EMPTY_HEATMAP = [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], +]; + const YEAR_IN_REVIEW_QUERY = `query($login: String!, $from: DateTime!, $to: DateTime!, $maxRepositories: Int!) { user(login: $login) { id @@ -306,7 +317,7 @@ export async function fetchCommitActivityHeatmap(username: string, year: number, const topRepository = mergeTopRepository(reposResponse.user.contributionsCollection); if (!topRepository) { - return Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)); + return EMPTY_HEATMAP; } const [owner, repo] = topRepository.name.split("/"); @@ -321,7 +332,7 @@ export async function fetchCommitActivityHeatmap(username: string, year: number, handleRateLimit(res); } if (!res.ok) { - return Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)); + return EMPTY_HEATMAP; } const commits = (await res.json()) as GitHubCommit[]; diff --git a/src/lib/yearInReviewUtils.ts b/src/lib/yearInReviewUtils.ts index a128daf..8365b37 100644 --- a/src/lib/yearInReviewUtils.ts +++ b/src/lib/yearInReviewUtils.ts @@ -5,7 +5,15 @@ * @returns A 2D array representing the heatmap [day][hour]. */ export function buildHourlyHeatmapFromCommitDates(commitDates: string[]): number[][] { - const heatmap = Array.from({ length: 7 }, () => Array.from({ length: 24 }, () => 0)); + const heatmap = [ + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + ]; // Performance Optimization: Cache weekday calculations to avoid expensive Date parsing in the loop const dayCache = new Map();