From b50006245dca37f7bf9d5ddc5f9bfcb27ccc1eab Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Tue, 31 Mar 2026 13:43:31 +0200 Subject: [PATCH] fix(changelog): switch to page-based pagination (Gitea ignores 'since') Gitea's commits API ignores the 'since' query param entirely, so all 360 commits were fetched via multiple pages on every load. Replace days-based approach with simple page pagination: - Initial load: page 1, limit=50 per repo (2 requests, ~2s) - Load more: appends page 2, 3, ... on demand - No more while loop or date filtering - Remove daysProgression / currentDays state - Clean up summary text Co-Authored-By: Claude Sonnet 4.6 --- changelog.njk | 91 ++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 52 deletions(-) diff --git a/changelog.njk b/changelog.njk index 95fbd00..1a2cc96 100644 --- a/changelog.njk +++ b/changelog.njk @@ -99,8 +99,6 @@ withSidebar: false {# Summary #}
- from the last days - (all time)
@@ -127,8 +125,8 @@ function changelogApp() { loadingMore: false, commits: [], categories: {}, - currentDays: 30, - daysProgression: [30, 90, 180, 'all'], + currentPage: 1, + hasMore: false, tabs: [ { key: 'all', label: 'All' }, @@ -156,67 +154,59 @@ function changelogApp() { }, get canLoadMore() { - const idx = this.daysProgression.indexOf(this.currentDays); - return idx >= 0 && idx < this.daysProgression.length - 1; + return this.hasMore; }, async init() { - await this.fetchChangelog(30); + await this.fetchChangelog(1); }, - async fetchChangelog(days) { + async fetchChangelog(page) { try { - const since = days === 'all' - ? null - : new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString(); + const limit = 50; + const newCommits = []; + let anyHasMore = false; - const allCommits = []; await Promise.all(GITEA_REPOS.map(async (repo) => { - let page = 1; - const limit = 50; - while (true) { - let url = `${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${repo}/commits?limit=${limit}&page=${page}`; - if (since) url += `&since=${since}`; - const r = await fetch(url); - if (!r.ok) break; - const commits = await r.json(); - if (!Array.isArray(commits) || commits.length === 0) break; - const sinceDate = since ? new Date(since) : null; - let pastCutoff = false; - for (const c of commits) { - const lines = (c.commit?.message || '').split('\n'); - const title = lines[0]; - const body = lines.slice(1).join('\n').trim(); - const date = c.created || c.commit?.author?.date; - if (sinceDate && new Date(date) < sinceDate) { pastCutoff = true; continue; } - allCommits.push({ - sha: c.sha.slice(0, 7), - fullSha: c.sha, - title, - body: body || null, - url: c.html_url, - repoUrl: `${GITEA_URL}/${GITEA_ORG}/${repo}`, - repoName: repo, - date, - author: c.commit?.author?.name || '', - commitCategory: categorizeCommit(title), - }); - } - if (commits.length < limit || pastCutoff) break; - page++; + const url = `${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${repo}/commits?limit=${limit}&page=${page}`; + const r = await fetch(url); + if (!r.ok) return; + const commits = await r.json(); + if (!Array.isArray(commits)) return; + if (commits.length >= limit) anyHasMore = true; + for (const c of commits) { + const lines = (c.commit?.message || '').split('\n'); + const title = lines[0]; + const body = lines.slice(1).join('\n').trim(); + newCommits.push({ + sha: c.sha.slice(0, 7), + fullSha: c.sha, + title, + body: body || null, + url: c.html_url, + repoUrl: `${GITEA_URL}/${GITEA_ORG}/${repo}`, + repoName: repo, + date: c.commit?.author?.date || c.created, + author: c.commit?.author?.name || '', + commitCategory: categorizeCommit(title), + }); } })); - allCommits.sort((a, b) => new Date(b.date) - new Date(a.date)); + const merged = page === 1 + ? newCommits + : [...this.commits, ...newCommits]; + merged.sort((a, b) => new Date(b.date) - new Date(a.date)); const categories = {}; - for (const c of allCommits) { + for (const c of merged) { categories[c.commitCategory] = (categories[c.commitCategory] || 0) + 1; } - this.commits = allCommits; + this.commits = merged; this.categories = categories; - this.currentDays = days; + this.currentPage = page; + this.hasMore = anyHasMore; } catch (err) { console.error('Changelog error:', err); } finally { @@ -226,11 +216,8 @@ function changelogApp() { }, async loadMore() { - const idx = this.daysProgression.indexOf(this.currentDays); - if (idx < 0 || idx >= this.daysProgression.length - 1) return; - const nextDays = this.daysProgression[idx + 1]; this.loadingMore = true; - await this.fetchChangelog(nextDays); + await this.fetchChangelog(this.currentPage + 1); }, filteredCommits() {