In your function getBodyType
I would add the subType
to the set before calling the db. If you add to the set in the then
clause it will be deferred and processing of the next row may indeed attempt to add the same subType
again. You already know that the subType
is not in the set, so why not add it right away before any other row is processed?
export async function getBodyType(body, conn, map) {
let subType = body.subType || "Other";
if (subType && !map.has(subType)) {
// Insert into the DB as we go, adding it to a set to ensure we don't duplicate
map.add(subType);
db.insertBodyType(subType, conn);
}
return subType;
}