Skip to content

Commit

Permalink
fix repair blob
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Nov 8, 2023
1 parent fd4f44d commit 93dd22e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/pds/src/migrate-script/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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()
}

0 comments on commit 93dd22e

Please sign in to comment.