paths.ts
This file
Path
packages/project/src/code/paths.ts
114 lines · 3.1 KiB · TypeScript
Last changed by
Merge perf/code-store into mainoscabrielbefore adoptionef0ddbd
History of this fileTake it
The walk stopped after 200 commits: lines older than 958650a point at it.
Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
lines 1–14why, one step back1import type {2 RepoHost,3 RepoNotFound,4 TreeEntry,5} from "@repo/artifacts/repo-host";6import type { PathList, Rev } from "@repo/protocol/domain/code";7import { RepoPath } from "@repo/protocol/ids";8import type { RepoName } from "@repo/protocol/ids";9import type { UnknownRevision } from "@repo/protocol/refusal";10import type { Option } from "effect";11import { Array, Effect, Order } from "effect";1213import type { CodeProject } from "../code.ts";14import { CodeCache } from "./cache.ts";Merge perf/code-store into mainoscabrielbefore adoptionef0ddbd
line 15why, one step back15import { keptOnlyIfCanonical } from "./history.ts";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 16why, one step back16import { commitAt, resolveAt } from "./revision.ts";Merge perf/code-store into mainoscabrielbefore adoptionef0ddbd
line 17why, one step back17import type { Resolved } from "./revision.ts";Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
lines 18–35why, one step back18import { entriesOf } from "./tree.ts";1920export const PATHS_CAP = 50_000;2122const KEPT_PATHS = 10_000;2324const STORE_CALLS = 8;2526export interface FileAt {27 readonly path: RepoPath;28 readonly entry: TreeEntry;29}3031interface Folder {32 readonly prefix: string;33 readonly tree: string;34}35Merge build/comments-project into mainoscabrielbefore adoption49efd2a
line 36why, one step back36/** One depth at a time, so the list past `cap` depends on the tree alone, never on which read came back first. */Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
lines 37–86why, one step back37export const filesUnder = (38 repo: RepoName,39 root: string,40 cap: number41): Effect.Effect<42 { readonly files: readonly FileAt[]; readonly truncated: boolean },43 RepoNotFound,44 RepoHost45> =>46 Effect.gen(function* () {47 const found: FileAt[] = [];48 let depth: readonly Folder[] = [{ prefix: "", tree: root }];4950 while (depth.length > 0 && found.length <= cap) {51 const read = yield* Effect.forEach(52 depth,53 ({ prefix, tree }) =>54 Effect.map(entriesOf(repo, tree), (entries) => ({ entries, prefix })),55 { concurrency: STORE_CALLS }56 );5758 const deeper: Folder[] = [];5960 for (const { entries, prefix } of read) {61 for (const entry of entries) {62 if (entry.type === "tree") {63 deeper.push({ prefix: `${prefix}${entry.name}/`, tree: entry.sha });64 } else {65 found.push({66 entry,67 path: RepoPath.make(`${prefix}${entry.name}`),68 });69 }70 }71 }7273 depth = deeper;74 }7576 const all = Array.sort(77 found,78 Order.mapInput(Order.String, (file: FileAt) => file.path)79 );8081 return {82 files: all.slice(0, cap),83 truncated: all.length > cap || depth.length > 0,84 };85 });86Merge perf/code-store into mainoscabrielbefore adoptionef0ddbd
line 87why, one step back87const pathsAt = ({ commit, repo }: Resolved) =>Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
lines 88–90why, one step back88 Effect.gen(function* () {89 const cache = yield* CodeCache;90Merge redesign into mainoscabrielbefore adoptioncaedd21
line 91why, one step back91 const { tree } = yield* commitAt(repo, commit).pipe(Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
lines 92–96why, one step back92 Effect.flatMap(Effect.fromOption),93 Effect.orDie94 );9596 const { files, truncated } = yield* cacheMerge redesign into mainoscabrielbefore adoptioncaedd21
lines 97–100why, one step back97 .through(`${repo}:paths:${tree}`, filesUnder(repo, tree, PATHS_CAP), {98 heavy: true,99 keep: (list) => list.files.length <= KEPT_PATHS,100 })Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
lines 101–103why, one step back101 .pipe(Effect.orDie);102103 return { at: commit, paths: files.map(({ path }) => path), truncated };Merge perf/code-store into mainoscabrielbefore adoptionef0ddbd
lines 104–113why, one step back104 });105106export const pathList = (107 project: CodeProject,108 at: Option.Option<Rev>109): Effect.Effect<PathList, UnknownRevision, RepoHost> =>110 Effect.gen(function* () {111 const resolved = yield* resolveAt(project, at);112113 return yield* keptOnlyIfCanonical(resolved, pathsAt(resolved));Merge branch 'build/905-readme-markdown'oscabrielbefore adoption958650a
line 114why, one step back114 });