From 9e2c52d8ef3f5104a41959fe532ace154a8ad4b8 Mon Sep 17 00:00:00 2001 From: Anugerah Erlaut Date: Tue, 14 Sep 2021 17:52:06 +0700 Subject: [PATCH 1/3] testing scan response --- src/api/route-services/projects.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/api/route-services/projects.js b/src/api/route-services/projects.js index b909e197f..ca341db7b 100644 --- a/src/api/route-services/projects.js +++ b/src/api/route-services/projects.js @@ -96,6 +96,9 @@ class ProjectsService { const response = await dynamodb.scan(params).promise(); + console.log('Scan response :'); + console.log(response); + if (!response.Items.length) { return []; } @@ -123,6 +126,9 @@ class ProjectsService { }, }; + console.log('== PARAMS'); + console.log(params); + const data = await safeBatchGetItem(dynamodb, params); const existingProjectIds = new Set(data.Responses[this.tableName].map((entry) => { From bf491e50dfa9bc45a429e44505fc79bc427cb0ba Mon Sep 17 00:00:00 2001 From: Anugerah Erlaut Date: Tue, 14 Sep 2021 18:58:33 +0700 Subject: [PATCH 2/3] iterate over scan result --- src/api/route-services/projects.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/api/route-services/projects.js b/src/api/route-services/projects.js index ca341db7b..435994091 100644 --- a/src/api/route-services/projects.js +++ b/src/api/route-services/projects.js @@ -94,19 +94,30 @@ class ProjectsService { const dynamodb = createDynamoDbInstance(); - const response = await dynamodb.scan(params).promise(); - - console.log('Scan response :'); - console.log(response); + let response = await dynamodb.scan(params).promise(); if (!response.Items.length) { return []; } - const projectIds = response.Items.map( + const extractProjectIds = (resp) => resp.Items.map( (entry) => convertToJsObject(entry).projectId, ).filter((id) => id); + let projectIds = extractProjectIds(response); + + // Check if query exceeds limit + while (response.LastEvaluatedKey) { + params.ExclusiveStartKey = response.LastEvaluatedKey; + + // eslint-disable-next-line no-await-in-loop + response = await dynamodb.scan(params).promise(); + + const newProjectIds = extractProjectIds(response); + + projectIds = projectIds.concat(newProjectIds); + } + return this.getProjectsFromIds(new Set(projectIds)); } From 3185ccf6e6bcb07dca3d6394c31f44a3a0bf5a8e Mon Sep 17 00:00:00 2001 From: Anugerah Erlaut Date: Tue, 14 Sep 2021 19:04:30 +0700 Subject: [PATCH 3/3] remove console.log --- src/api/route-services/projects.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/api/route-services/projects.js b/src/api/route-services/projects.js index 435994091..74af91053 100644 --- a/src/api/route-services/projects.js +++ b/src/api/route-services/projects.js @@ -137,9 +137,6 @@ class ProjectsService { }, }; - console.log('== PARAMS'); - console.log(params); - const data = await safeBatchGetItem(dynamodb, params); const existingProjectIds = new Set(data.Responses[this.tableName].map((entry) => {