Skip to content

Commit

Permalink
fix: fix a number of bugs with ProvisionStore#getConsumer (#223)
Browse files Browse the repository at this point in the history
upgrade w3up to bring in new tests that would have caught these bugs
  • Loading branch information
travis authored Sep 5, 2023
1 parent e1c0507 commit ff92360
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion upload-api/functions/ucan-invocation-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function ucanInvocationRouter(request) {
CONSUMER_TABLE_NAME: consumerTableName = '',
SUBSCRIPTION_TABLE_NAME: subscriptionTableName = '',
DELEGATION_TABLE_NAME: delegationTableName = '',
SPACE_METRICS_TABLE: spaceMetricsTableName = '',
SPACE_METRICS_TABLE_NAME: spaceMetricsTableName = '',
RATE_LIMIT_TABLE_NAME: rateLimitTableName = '',
R2_ENDPOINT: r2DelegationBucketEndpoint = '',
R2_ACCESS_KEY_ID: r2DelegationBucketAccessKeyId = '',
Expand Down
2 changes: 1 addition & 1 deletion upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@web-std/fetch": "^4.1.0",
"@web3-storage/access": "^14.0.0",
"@web3-storage/capabilities": "^9.0.0",
"@web3-storage/upload-api": "^5.2.0",
"@web3-storage/upload-api": "^5.3.0",
"@web3-storage/w3infra-ucan-invocation": "*",
"multiformats": "^11.0.1",
"nanoid": "^4.0.2",
Expand Down
19 changes: 8 additions & 11 deletions upload-api/tables/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,17 @@ export function useConsumerTable (dynamoDb, tableName) {
const response = await dynamoDb.send(new QueryCommand({
TableName: tableName,
IndexName: 'consumer',
KeyConditionExpression: "consumer = :consumer and provider = :provider",
KeyConditionExpression: "consumer = :consumer",
ExpressionAttributeValues: {
':consumer': { S: consumer },
':provider': { S: provider }
},
}))
if (response.Items && (response.Items.length > 0)) {
const record = unmarshall(response.Items[0])
return {
subscription: record.subscription
}
} else {
return null
}
}))
// we may need to worry about pagination in the future if we end up supporting many many subscriptions for a single
// provider/consumer pair, but I suspect we'll never get there
const record = response.Items?.map(i => unmarshall(i)).find(i => i.provider === provider)
return record ? {
subscription: record.subscription
} : null
},

/**
Expand Down
5 changes: 2 additions & 3 deletions upload-api/tables/space-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ export function useSpaceMetricsTable(dynamoDb, tableName) {
const response = await dynamoDb.send(new GetItemCommand({
TableName: tableName,
Key: marshall({
consumer,
space: consumer,
name: METRICS_NAMES.STORE_ADD_SIZE_TOTAL
}),
AttributesToGet: ['value']
})
}))
return response.Item ? unmarshall(response.Item).value : 0
}
Expand Down

0 comments on commit ff92360

Please sign in to comment.