(db: Database, hashes: Uint8Array[])
| 45 | // rides the primary-key index. Present hashes are returned in input |
| 46 | // order, preserving any duplicates the caller passed. |
| 47 | export 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 | } |
no test coverage detected