Skip to content

fix: skip downloading CIDs for empty files #617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ export const preprocess = async ({
* @returns {Promise<import('./typings.js').RawMeasurement[]>}
*/
export const fetchMeasurements = async (cid, { signal, noCache = false } = {}) => {
if (cid === 'bafkqaaa' || cid === 'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku') {
// These CIDs represent an empty file
return []
}

const res = await fetch(
`https://${encodeURIComponent(cid)}.ipfs.w3s.link?format=car`,
{
Expand Down
17 changes: 16 additions & 1 deletion test/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
preprocess,
Measurement,
parseMeasurements,
assertValidMeasurement
assertValidMeasurement,
fetchMeasurements
} from '../lib/preprocess.js'
import { Point } from '../lib/telemetry.js'
import assert from 'node:assert'
Expand Down Expand Up @@ -86,6 +87,20 @@ describe('preprocess', () => {
})
})

describe('fetchMeasurements', () => {
it('handles empty batch with CID bafkqaaa', async () => {
const cid = 'bafkqaaa'
const measurements = await fetchMeasurements(cid)
assert.deepStrictEqual(measurements, [])
})

it('handles empty batch with CID bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku', async () => {
const cid = 'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'
const measurements = await fetchMeasurements(cid)
assert.deepStrictEqual(measurements, [])
})
})

describe('parseMeasurements', () => {
const measurements = [{ foo: 'bar' }, { beep: 'boop' }]
it('parses a JSON array', () => {
Expand Down