From 50f6b6dac9ea858faa7d5872ba4fbcb6a723b0bd Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Thu, 20 Aug 2026 01:09:42 +0900 Subject: [PATCH] web: fetch PR view from `/[version]` we don't need commit/change-id range Signed-off-by: Seongmin Lee --- .../[repo]/pulls/[aturi]/[version]/+layout.ts | 36 +++++++++++++++++++ .../[aturi]/[version]/[[range]]/+page.ts | 31 +++++----------- 2 files changed, 44 insertions(+), 23 deletions(-) create mode 100644 web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/+layout.ts diff --git a/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/+layout.ts b/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/+layout.ts new file mode 100644 index 00000000..4fc545d7 --- /dev/null +++ b/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/+layout.ts @@ -0,0 +1,36 @@ +import { redirect } from "@sveltejs/kit"; +import { createBobbinClient } from "$lib/api/client"; +import { listLog } from "$lib/api/gitmirror"; +import { isRedirect, parseDiffRoute, parseInterdiffRoute } from "$lib/api/pullRoute"; +import { countCommentsByCommit } from "$lib/components/comment/comments"; +import type { Did } from "@atcute/lexicons/syntax"; +import type { LayoutLoad } from "./$types"; + +export const load: LayoutLoad = async (event) => { + const parent = await event.parent(); + const { pull, sourceRepoDid } = parent; + + const route = event.params.version.includes("..") + ? parseInterdiffRoute(pull.versions, event.params.version) + : parseDiffRoute(pull.versions, event.params.version); + if (isRedirect(route)) { + const { handle, repo, aturi } = event.params; + redirect(307, `/${handle}/${repo}/pulls/${aturi}/latest`); + } + + const ctx = createBobbinClient({ + serviceUrl: parent.publicConfig.bobbinUrl, + fetch: event.fetch + }); + + // TODO: bobbin should hydrate the commit list with backlinked comment counts + const commits = await listLog(ctx, sourceRepoDid as Did, pull.versions[route.version]); + const commentCounts = countCommentsByCommit(parent.comments); + + return { + commits: commits.map((commit) => ({ + ...commit, + commentCount: commentCounts.get(commit.hash) ?? 0 + })) + }; +}; diff --git a/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/[[range]]/+page.ts b/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/[[range]]/+page.ts index 98b31e59..586bee29 100644 --- a/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/[[range]]/+page.ts +++ b/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/[[range]]/+page.ts @@ -1,36 +1,25 @@ import { redirect } from "@sveltejs/kit"; -import { createBobbinClient } from "$lib/api/client"; -import { listLog } from "$lib/api/gitmirror"; import { isRedirect, parseDiffRoute, parseInterdiffRoute } from "$lib/api/pullRoute"; -import { countCommentsByCommit } from "$lib/components/comment/comments"; -import type { Did } from "@atcute/lexicons/syntax"; import type { PageLoad } from "./$types"; +// nothing here touches the network: the commit list comes from the version layout, and +// resolving the range against it is arithmetic, so narrowing a range is a free navigation export const load: PageLoad = async (event) => { const parent = await event.parent(); - const uri = event.params.aturi; - const { pull, sourceRepoDid } = parent; - - const ctx = createBobbinClient({ - serviceUrl: parent.publicConfig.bobbinUrl, - fetch: event.fetch - }); + const { pull, commits } = parent; const route = event.params.version.includes("..") ? parseInterdiffRoute(pull.versions, event.params.version, event.params.range) : parseDiffRoute(pull.versions, event.params.version, event.params.range); if (isRedirect(route)) { - // a bad version falls back to the newest one, a bad range only drops itself - const target = route.redirect === "latest" ? "latest" : event.params.version; - redirect(307, `/${event.params.handle}/${event.params.repo}/pulls/${uri}/${target}`); + // the layout already vetted the version against the same parser, so the range is + // the only thing left that can be bad -- drop it and keep the version + const { handle, repo, aturi, version } = event.params; + redirect(307, `/${handle}/${repo}/pulls/${aturi}/${version}`); } const currentVersion = pull.versions[route.version]; - // TODO: bobbin should hydrate the commit list with backlinked comment counts - const commits = await listLog(ctx, sourceRepoDid as Did, currentVersion); - const commentCounts = countCommentsByCommit(parent.comments); - if (route.mode === "diff") { route.base = commits.find((commit) => commit.hash.startsWith(route.base))?.hash ?? @@ -44,11 +33,7 @@ export const load: PageLoad = async (event) => { } return { - commits: commits.map((commit) => ({ - ...commit, - commentCount: commentCounts.get(commit.hash) ?? 0 - })), view: route, - uri + uri: event.params.aturi }; }; -- 2.51.2