warmUp

tcmts.share.warmUp · #7twncnvy · term · runs on the server

uses tcmts.share.roleNow, which uses tcmts.cli.pages.roleOf, which uses tcmts.cli.roles.codebaseRoles, which uses tcmts.cli.roles.rolesIn, which uses tcmts.cli.roles.manifestsIn, which uses tcmts.cli.config.configValue, which uses node:path

Make what the pages read of the branch's head before they're asked for it, as they'd make it: what each definition is for (and where it runs), the front page's map, how many history entries there are, and the history's first ten pages, in the background (inSlices); it stops if the head moves.

import { historyList } from "#codebase/tcmts/cli/changes";
import {
  childrenOf, entriesIn, entrySummary, inSlices, namesNow, placeMix, projectNow, roleNow,
} from "#codebase/tcmts/share";
import type { Share } from "#codebase/tcmts/share";

export async function warmUp(s: Pick<Share, "cb" | "cache">, slice = 10): Promise<void> {
  const head = s.cb.store.head();
  const rows = namesNow(s);
  // (a definition at a time: placing one places what it uses, so the first few take longest)
  const steps: (() => unknown)[] = [
    ...rows.map((r) => () => roleNow(s, r)),
    ...childrenOf(rows, projectNow(s).root).namespaces.map(
      (n) => () => placeMix(s, n.rows, n.name),
    ),
    () => entriesIn(s, head),
    // (an entry never changes: after a push, only the new ones take any time)
    ...historyList(s.cb, 300).map((h) => () => entrySummary(s, h.hash)),
  ];
  await inSlices(steps, () => s.cb.store.head() === head, { slice, background: true });
}

uses

used by