Skip to content

Commit

Permalink
Merge pull request #226 from biomage-ltd/fix-fetching-projects
Browse files Browse the repository at this point in the history
Handle scan limit
  • Loading branch information
aerlaut authored Sep 14, 2021
2 parents dfda76f + 3185ccf commit 172387d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/api/route-services/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,30 @@ class ProjectsService {

const dynamodb = createDynamoDbInstance();

const response = await dynamodb.scan(params).promise();
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));
}

Expand Down

0 comments on commit 172387d

Please sign in to comment.