File
Blob: src/worker/git/object-store/lookup.ts
| 1 | import type { CacheContext } from "@/worker/cache"; |
| 2 | |
| 3 | import { loadActivePackCatalog } from "./catalog"; |
| 4 | import { findFirstPackedObjectCandidate, type IndexedPackSource } from "./candidates"; |
| 5 | import { loadIdxView } from "./idxView"; |
| 6 | import { ensureMemo, getPackedObjectStoreLogger, logOnce, type ResolvedLocation } from "./support"; |
| 7 | |
| 8 | export async function findObject( |
| 9 | env: Env, |
| 10 | repoId: string, |
| 11 | oid: string, |
| 12 | cacheCtx?: CacheContext |
| 13 | ): Promise<ResolvedLocation | undefined> { |
| 14 | ensureMemo(cacheCtx, repoId); |
| 15 | const log = getPackedObjectStoreLogger(env, repoId); |
| 16 | const packs = await loadActivePackCatalog(env, repoId, cacheCtx); |
| 17 | let packsScanned = 0; |
| 18 | |
| 19 | for (const pack of packs) { |
| 20 | packsScanned++; |
| 21 | const idx = await loadIdxView(env, pack.packKey, cacheCtx, pack.packBytes); |
| 22 | if (!idx) continue; |
| 23 | |
| 24 | const source: IndexedPackSource = { |
| 25 | packKey: pack.packKey, |
| 26 | packBytes: pack.packBytes, |
| 27 | idx, |
| 28 | }; |
| 29 | const candidate = findFirstPackedObjectCandidate([source], oid); |
| 30 | if (!candidate) continue; |
| 31 | |
| 32 | logOnce(cacheCtx, "packed-chosen-pack-logged", () => { |
| 33 | log.debug("chosen-pack", { |
| 34 | oid: oid.toLowerCase(), |
| 35 | packKey: pack.packKey, |
| 36 | packsScanned, |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | return { |
| 41 | ...candidate, |
| 42 | packSlot: packsScanned - 1, |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | log.debug("packed-object:miss", { oid: oid.toLowerCase(), packsScanned }); |
| 47 | return undefined; |
| 48 | } |