Skip to content

Commit

Permalink
fix(billing): skip batchPut if no space diff (#4)
Browse files Browse the repository at this point in the history
Issue: storacha/project-tracking#185

Potential Fix: if there are no records for that `.list({consumer:
delta.resource})` in the `consumerStore`, it will return an empty array,
then it won't generate any space diff to be stored, and it will throw
the error when we execute the `batchPut` call. The fix skips the
`batchPut` call when no diffs are available.
  • Loading branch information
fforbeck authored Nov 18, 2024
1 parent c6be8c1 commit bb75602
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions billing/lib/ucan-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ export const storeSpaceUsageDeltas = async (deltas, ctx) => {
spaceDiffs.push(...res.ok)
}

if (spaceDiffs.length === 0) return {
ok: 'no space diffs to store',
error: undefined
}

return ctx.spaceDiffStore.batchPut(spaceDiffs)
}

Expand Down
2 changes: 1 addition & 1 deletion billing/test/lib/ucan-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export const test = {

const deltas = findSpaceUsageDeltas(receipts)
const storeDeltasRes = await storeSpaceUsageDeltas(deltas, ctx)
assert.equal(storeDeltasRes.error?.name, 'InsufficientRecords')
assert.equal(storeDeltasRes.ok, 'no space diffs to store')

const res = await ctx.spaceDiffStore.list({
provider: consumer.provider,
Expand Down

0 comments on commit bb75602

Please sign in to comment.