Skip to content
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

Replace dynamodb scan with query #31

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ jobs:
github-action:
uses: cloudposse/.github/.github/workflows/shared-github-action.yml@main
secrets: inherit

10 changes: 6 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185422,8 +185422,8 @@ class DynamoDBMetadataRepo {
return __awaiter(this, void 0, void 0, function* () {
const params = {
TableName: this.tableName,
ExclusiveStartKey: undefined,
FilterExpression: "#owner = :owner and #repo = :repo and #commitSHA = :commitSHA and #component = :component and #stack = :stack",
KeyConditionExpression: "#commitSHA= :commitSHA",
FilterExpression: "#owner = :owner and #repo = :repo and #component = :component and #stack = :stack",
ExpressionAttributeNames: {
"#owner": "repoOwner",
"#repo": "repoName",
Expand All @@ -185438,12 +185438,14 @@ class DynamoDBMetadataRepo {
":component": component,
":stack": stack
},
ProjectionExpression: projectionExpression
ProjectionExpression: projectionExpression,
IndexName: "commitSHA-index",
ScanIndexForward: false
};
let results = [];
let response;
do {
const command = new lib_dynamodb_1.ScanCommand(params);
const command = new lib_dynamodb_1.QueryCommand(params);
response = yield this.dynamo.send(command);
if (response.Items && response.Items.length >= 0) {
results = results.concat(response.Items);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions src/modules/terraformPlan/repo/DynamoDbMetadataRepo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {
DynamoDBDocumentClient,
ScanCommandInput,
ScanCommandOutput,
ScanCommand,
QueryCommandInput,
QueryCommandOutput,
QueryCommand,
PutCommand,
PutCommandInput
Expand Down Expand Up @@ -32,11 +30,11 @@ export class DynamoDBMetadataRepo implements IMetadataRepository {
stack: string,
commitSHA: string
): Promise<TerraformPlan> {
const params: ScanCommandInput = {
const params: QueryCommandInput = {
TableName: this.tableName,
ExclusiveStartKey: undefined,
KeyConditionExpression: "#commitSHA= :commitSHA",
FilterExpression:
"#owner = :owner and #repo = :repo and #commitSHA = :commitSHA and #component = :component and #stack = :stack",
"#owner = :owner and #repo = :repo and #component = :component and #stack = :stack",
ExpressionAttributeNames: {
"#owner": "repoOwner",
"#repo": "repoName",
Expand All @@ -51,14 +49,14 @@ export class DynamoDBMetadataRepo implements IMetadataRepository {
":component": component,
":stack": stack
},
ProjectionExpression: projectionExpression
ProjectionExpression: projectionExpression,
IndexName: "commitSHA-index",
ScanIndexForward: false
};

let results : Record<string, NativeAttributeValue>[] = []
let response : ScanCommandOutput

let response: QueryCommandOutput
do {
const command = new ScanCommand(params);
const command = new QueryCommand(params);
response = await this.dynamo.send(command);

if (response.Items && response.Items.length >= 0) {
Expand Down
Loading