From 93dd22eee257bdb510923f265c55ad58b3659410 Mon Sep 17 00:00:00 2001 From: dholms Date: Wed, 8 Nov 2023 15:47:46 -0600 Subject: [PATCH] fix repair blob --- packages/pds/src/migrate-script/util.ts | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/pds/src/migrate-script/util.ts b/packages/pds/src/migrate-script/util.ts index 8de51daaf8c..cb6fe5c1931 100644 --- a/packages/pds/src/migrate-script/util.ts +++ b/packages/pds/src/migrate-script/util.ts @@ -53,6 +53,21 @@ export const repairBlob = async ( did: string, cid: string, adminHeaders: AdminHeaders, +) => { + await repairBlobInternal(ctx, pds, did, cid, adminHeaders) + await db + .deleteFrom('failed_blob') + .where('did', '=', did) + .where('cid', '=', cid) + .execute() +} + +export const repairBlobInternal = async ( + ctx: AppContext, + pds: PdsInfo, + did: string, + cid: string, + adminHeaders: AdminHeaders, ) => { const blob = await ctx.db.db .selectFrom('blob') @@ -65,13 +80,7 @@ export const repairBlob = async ( try { blobStream = await ctx.blobstore.getStream(CID.parse(blob.cid)) } catch (err) { - const hasTakedown = await ctx.db.db - .selectFrom('repo_blob') - .where('did', '=', did) - .where('cid', '=', cid) - .where('takedownRef', 'is not', null) - .executeTakeFirst() - if (hasTakedown) { + if (err?.['Code'] === 'NoSuchKey') { return } throw err @@ -85,9 +94,4 @@ export const repairBlob = async ( decompress: true, responseType: 'stream', }) - await db - .deleteFrom('failed_blob') - .where('did', '=', did) - .where('cid', '=', blob.cid) - .execute() }