async function getPartitionMaxProcessedFileNumber()

in source/lambda/requestArchives/lib/db.js [63:91]


async function getPartitionMaxProcessedFileNumber(pid) {
    console.log(`Checking last file number for partition : ${pid}`);
    let result = await dynamodb
        .query({
            TableName: STATUS_TABLE,
            IndexName: "max-file-index",
            KeyConditionExpression: "pid = :pid",
            ExpressionAttributeValues: {
                ":pid": {N: pid.toString()},
            },
            ProjectionExpression: "ifn, aid",
            ScanIndexForward: false,
            Limit: 1,
        })
        .promise();

    if (result.Count == 0) {
        console.log(
            `No records for partition ${pid} found. Setting the last item number to 0`
        );
        return 0;
    }

    const lastIfn =  result.Items[0].ifn.N;
    const aid =  result.Items[0].aid.S;

    console.log(`Last registered item is ${lastIfn}. ArchiveID (aid): ${aid} `);
    return lastIfn;
}