File
Blob: src/worker/git/operations/closure.ts
| 1 | import type { CacheContext } from "@/worker/cache"; |
| 2 | |
| 3 | import { createLogger } from "@/worker/common"; |
| 4 | import { hasObjectsBatch } from "@/worker/git/object-store"; |
| 5 | |
| 6 | /** |
| 7 | * Finds the subset of client-advertised haves that the server can already |
| 8 | * satisfy from the active pack snapshot. |
| 9 | */ |
| 10 | export async function findCommonHaves( |
| 11 | env: Env, |
| 12 | repoId: string, |
| 13 | haves: string[], |
| 14 | cacheCtx?: CacheContext |
| 15 | ): Promise<string[]> { |
| 16 | const limit = 128; |
| 17 | const cappedHaves = haves.slice(0, limit); |
| 18 | const present = await hasObjectsBatch(env, repoId, cappedHaves, cacheCtx); |
| 19 | |
| 20 | const found: string[] = []; |
| 21 | const seen = new Set<string>(); |
| 22 | for (let index = 0; index < present.length; index++) { |
| 23 | const oid = cappedHaves[index]?.toLowerCase(); |
| 24 | if (!oid || seen.has(oid) || !present[index]) continue; |
| 25 | seen.add(oid); |
| 26 | found.push(oid); |
| 27 | } |
| 28 | |
| 29 | const log = createLogger(env.LOG_LEVEL, { service: "FindCommonHaves", repoId }); |
| 30 | log.debug("common:haves", { |
| 31 | requested: cappedHaves.length, |
| 32 | found: found.length, |
| 33 | }); |
| 34 | return found; |
| 35 | } |