web/repo: the sidebar keeps every ref, so commit pages name refs without listing them again
Signed-off-by: dawn <90008@klbr.net>
18 unmodified lines1920212223232425262728128 unmodified linesExpand all1571581591601601611621621631641651661673 unmodified lines17117217317417517617717817918018118218318418518618718818 unmodified linesimport type { RepoParent } from "#lib/api/repoLoad.ts";import type { LanguageSlice } from "#lib/components/repo/types.ts";import type { Fetch } from "#lib/fetch.ts";
// static knots only answer REF_LIMIT sized pages// the refs the sidebar draws. it keeps every ref up to REF_LIMIT (the most static knots// answer in a page), so a page that names a commit's refs reads them from itexport const SIDEBAR_BRANCHES = 6;export const SIDEBAR_TAGS = 4;
export interface RepoSidebar {128 unmodified linesExpand all const tagList = (tags.value?.tags ?? []).map(toTagSummary); return { ref: target, files: sortTreeEntries((tree.value?.files ?? []).map(toTreeEntrySummary)), branches: branchList.slice(0, SIDEBAR_BRANCHES), branches: branchList, totalBranches: branches.value?.total ?? branchList.length, tags: tagList.slice(0, SIDEBAR_TAGS), tags: tagList, totalTags: tags.value?.total ?? tagList.length, languages: toLanguageSlices( onDefault ? repo.git.languages! : (languages?.value?.languages ?? []) ),3 unmodified lines languages: languages !== null && languages.value === null } };};
/** every ref of the repo, from the sidebar when it holds them all */export const repoRefs = async ( sidebar: RepoSidebar | null | Promise<RepoSidebar | null>, read: () => Promise<{ tags: TagSummary[]; branches: BranchSummary[] }>): Promise<{ tags: TagSummary[]; branches: BranchSummary[] }> => { const held = await Promise.resolve(sidebar).catch(() => null); const whole = held && !held.failed.refs && held.branches.length === held.totalBranches && held.tags.length === held.totalTags; return whole ? { tags: held.tags, branches: held.branches } : read();};5 unmodified lines6789101112131415200 unmodified linesExpand all21621721821921822022122022222322422522671 unmodified lines5 unmodified lines import { sortTreeEntries, toTreeEntrySummary } from "#lib/api/repo.ts"; import { findCompact, folderChain, SIDEBAR_BRANCHES, SIDEBAR_TAGS, TREE_DEPTH, treeRoot, type Compact, type FolderListings,200 unmodified linesExpand all {#if sidebar.branches.length + sidebar.tags.length > 0 || sidebar.failed.refs} <RefsWindow ownerHandle={repo.ownerHandle} repoName={repo.name} branches={sidebar.branches} branches={sidebar.branches.slice(0, SIDEBAR_BRANCHES)} totalBranches={sidebar.totalBranches} tags={sidebar.tags} tags={sidebar.tags.slice(0, SIDEBAR_TAGS)} totalTags={sidebar.totalTags} current={sidebar.ref} failed={sidebar.failed.refs} />71 unmodified lines19 unmodified lines20212223242526272881 unmodified lines11011111211311311411511611711811912012112212312412512612712812913013113213313413513613713811411511611711811912012112212312412512612712812912 unmodified lines19 unmodified lines} from "#lib/api/repoDiff.ts";
import { refNamesByCommitHash, toBranchSummary, toTagSummary } from "#lib/api/repo.ts";import { REF_LIMIT, withAuthorHandles } from "#lib/api/repoIndex.ts";import { repoRefs } from "#lib/api/repoSidebar.ts";import type { Did } from "@atcute/lexicons/syntax";import type { PageLoad } from "./$types";
export const load: PageLoad = async (event) => {81 unmodified lines
const refNames = live( () => commitPage.then(async ({ repoDid, commit }) => { // the sidebar holds every ref of a repo with few of them, the lists are read again // only past that const sidebar = await Promise.resolve(parent.sidebar).catch(() => null); if ( sidebar && !sidebar.failed.refs && sidebar.branches.length === sidebar.totalBranches && sidebar.tags.length === sidebar.totalTags ) return ( refNamesByCommitHash([commit], sidebar.tags, sidebar.branches)[ commit.hash ] ?? [] ); const git = knotMirrorTarget(parent.publicConfig, { repoDid }, event.fetch); const [tagRes, branchRes] = await Promise.all([ tags(git, REF_LIMIT).catch(() => ({ tags: [] })), branches(git, REF_LIMIT).catch(() => ({ branches: [] })) ]); return ( refNamesByCommitHash( [commit], (tagRes.tags ?? []).map(toTagSummary), (branchRes.branches ?? []).map((b) => toBranchSummary(b)) )[commit.hash] ?? [] ); const refs = await repoRefs(parent.sidebar, async () => { const git = knotMirrorTarget(parent.publicConfig, { repoDid }, event.fetch); const [tagRes, branchRes] = await Promise.all([ tags(git, REF_LIMIT).catch(() => ({ tags: [] })), branches(git, REF_LIMIT).catch(() => ({ branches: [] })) ]); return { tags: (tagRes.tags ?? []).map(toTagSummary), branches: (branchRes.branches ?? []).map((b) => toBranchSummary(b)) }; }); return refNamesByCommitHash([commit], refs.tags, refs.branches)[commit.hash] ?? []; }), [] as string[] );
12 unmodified lines1234567841 unmodified lines50515253545556535455565758596061625758596061626364656667686970717264737475676876777879808117 unmodified linesimport { branch, branches, gitTarget, log, requireGit, tags } from "#lib/api/gitclient.ts";import { toMirrorCommitSummary } from "#lib/api/knotmirror.ts";import { REF_LIMIT, withAuthorHandles } from "#lib/api/repoIndex.ts";import { repoRefs } from "#lib/api/repoSidebar.ts";import { refNamesByCommitHash, toBranchSummary, toTagSummary } from "#lib/api/repo.ts";import { error } from "@sveltejs/kit";import { httpStatusFor, live, settle, stream, toHttpError } from "#lib/api/load.ts";import { COMMIT_PAGE_SIZE } from "#lib/commitPaging.ts";41 unmodified lines });
let refsPromise: ReturnType<typeof fetchRefs> | undefined; const fetchRefs = () => repoRefs(parent.sidebar, async () => { const [tagRes, branchRes] = await Promise.all([ repoPromise Promise.all([ repoPromise .then((repo) => tags(gitTarget(parent.publicConfig, repo, event.fetch), REF_LIMIT)) .catch(() => ({ tags: [] })), repoPromise .then((repo) => branches(gitTarget(parent.publicConfig, repo, event.fetch), REF_LIMIT) ) .catch(() => ({ branches: [] })) ]); .then((repo) => tags(gitTarget(parent.publicConfig, repo, event.fetch), REF_LIMIT) ) .catch(() => ({ tags: [] })), repoPromise .then((repo) => branches(gitTarget(parent.publicConfig, repo, event.fetch), REF_LIMIT) ) .catch(() => ({ branches: [] })) ]); return { tags: (tagRes.tags ?? []).map(toTagSummary), branches: (branchRes.branches ?? []).map((b) => toBranchSummary(b)) }; }); const namesFor = async (commitList: CommitSummary[]) => { const [tagRes, branchRes] = await (refsPromise ??= fetchRefs()); const refs = await (refsPromise ??= fetchRefs()); return refNamesByCommitHash( commitList, (tagRes.tags ?? []).map(toTagSummary).filter((t) => t.name !== ref), (branchRes.branches ?? []).map((b) => toBranchSummary(b)).filter((b) => b.name !== ref) refs.tags.filter((t) => t.name !== ref), refs.branches.filter((b) => b.name !== ref) ); };
const tagsByCommit = live(() => commits.then(namesFor), {});17 unmodified lines