Skip to content

Commit

Permalink
Fix empty search report batch delete call
Browse files Browse the repository at this point in the history
  • Loading branch information
amits97 committed Nov 18, 2024
1 parent fa72064 commit e1c947f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions api/analytics-service/empty-search-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ import * as usernameLib from "../libs/username-lib";
import * as emailLib from "../libs/email-lib";
import { success, failure } from "../libs/response-lib";

async function deleteItems(deleteRequestArray) {
const deleteParams = {
RequestItems: {
NaadanChordsEmptySearch: deleteRequestArray,
},
ReturnItemCollectionMetrics: "SIZE",
ConsumedCapacity: "INDEXES",
};

await dynamoDbLib.batchCall(deleteParams);
}

async function clearTable() {
const previousPositions = [];
let params = {
TableName: "NaadanChordsEmptySearch",
ScanIndexForward: false,
Expand All @@ -15,7 +26,6 @@ async function clearTable() {

let deleteRequestArray = [];
for (let i = 0; i < resultArray.length; i++) {
previousPositions.push(resultArray[i].timestamp);
let deleteItem = {
DeleteRequest: {
Key: {
Expand All @@ -27,17 +37,10 @@ async function clearTable() {
}

if (deleteRequestArray.length > 0) {
const deleteParams = {
RequestItems: {
NaadanChordsEmptySearch: deleteRequestArray,
},
ReturnItemCollectionMetrics: "SIZE",
ConsumedCapacity: "INDEXES",
};

await dynamoDbLib.batchCall(deleteParams);
while (deleteRequestArray.length) {
await deleteItems(deleteRequestArray.splice(0, 25));
}
}
return previousPositions;
}

function removeDuplicates(result) {
Expand Down

0 comments on commit e1c947f

Please sign in to comment.