MCPcopy Create free account
hub / github.com/cloudflare/computer / hasObjects

Function hasObjects

packages/dofs/src/sync/fetch.ts:47–64  ·  view source on GitHub ↗
(db: Database, hashes: Uint8Array[])

Source from the content-addressed store, hash-verified

45// rides the primary-key index. Present hashes are returned in input
46// order, preserving any duplicates the caller passed.
47export function hasObjects(db: Database, hashes: Uint8Array[]): Uint8Array[] {
48 if (hashes.length === 0) return [];
49 const present = new Set<string>();
50 for (let i = 0; i < hashes.length; i += PROBE_BATCH) {
51 const window = hashes.slice(i, i + PROBE_BATCH);
52 const placeholders = window.map(() => "?").join(", ");
53 const rows = db.all<{ hash: Uint8Array }>(
54 `SELECT b.hash
55 FROM vfs_blobs b
56 JOIN vfs_blob_bytes bb ON bb.hash = b.hash
57 WHERE b.hash IN (${placeholders})
58 AND length(bb.bytes) = b.size`,
59 ...window,
60 );
61 for (const row of rows) present.add(toHex(row.hash));
62 }
63 return hashes.filter((h) => present.has(toHex(h)));
64}

Callers 3

pullOnceImplFunction · 0.90
hasObjectsMethod · 0.90
fetch.test.tsFile · 0.70

Calls 4

allMethod · 0.80
hasMethod · 0.80
toHexFunction · 0.70
addMethod · 0.65

Tested by

no test coverage detected