Skip to content
Myr

Read a file's view in one call when a file is there

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- On a cold isolate the view read the commit, each folder above the file one after another, then its blob: 1.5-1.7 s live for changesets' six-deep test files, so a why page whose why came from the store still took about 2 s on a fresh isolate (after a redeploy, every isolate). - fileView now reads the file whole at the commit (RepoHost readFile, one call), names it by its git blob id, and keeps it in the isolate's cache by (commit, path) when within KEPT_TEXT. A folder, a submodule, a missing path, or a file Artifacts will not hold (MEMORY_LIMIT) is looked up by its folders as before, so UnknownPath and the truncated view are unchanged. - ASSUMPTION: Artifacts' readFile gives a symlink's own blob, as the tree does; none of the repos read live has a symlink to check it on. - Test (red first, code-history.test.ts): a cold isolate reads the file in one call and nothing else (was a commit, the folders and a blob), and the same isolate reads nothing the second time.

authored by oscabriel · committed by oscabriel · parent 69fe19f · Browse files · 2 files+107 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+107 added−15 removed

  • tests:+43 added−1 removed
  • other:+64 added−14 removed

2 files+107 added−15 removed

modified:packages/project/src/code/file.ts+64 added-14 removed
modified:packages/project/test/code-history.test.ts+43 added-1 removed
24 unmodified lines
25import { DateTime, Duration, Effect, Layer, Option, Ref, Schema } from "effect";2627import { CodeStore } from "../src/code-store.ts";28import { CodeStoreCounts, CodeStoreMemory } from "../src/code-store/memory.ts";29import { logOf, whyOf } from "../src/code.ts";29import { fileOf, logOf, whyOf } from "../src/code.ts";30import type { CodeProject } from "../src/code.ts";31import { CodeCache, CodeCacheLive } from "../src/code/cache.ts";32import type { CodeReads } from "../src/code/cache.ts";33import { FILE_WALK_CAP } from "../src/code/file-walk.ts";
851 unmodified lines
885 })886 )887 );888});889890describe("a file's view", () => {891 it.effect(892 "reads the file in one call on a cold isolate, and nothing again on the same isolate",893 () =>894 within(({ seen }) =>895 Effect.gen(function* () {896 const { grown } = yield* history;897 const { code } = yield* recordOf(grown);898899 yield* Ref.set(seen, none);900901 const { first, again, cold } = yield* onIsolate(902 Effect.gen(function* () {903 const read = yield* fileOf(code, Option.none(), format);904 const coldReads = yield* Ref.get(seen);905906 yield* Ref.set(seen, none);907908 return {909 again: yield* fileOf(code, Option.none(), format),910 cold: coldReads,911 first: read,912 };913 })914 );915916 const { blobs, commits, files, trees } = cold;917918 expect(first.text).toBe("a\nx\ny\niso, changed\nb\nweek\n");919 expect(again).toStrictEqual(first);920 expect({ blobs, commits, files, trees }).toStrictEqual({921 blobs: 0,922 commits: 0,923 files: 1,924 trees: 0,925 });926 expect(yield* Ref.get(seen)).toStrictEqual(none);927 })928 )929 );930});