Fix set bug and use more efficient vars

Signed-off-by: Damon Kaswell <damon.kaswell1@hp.com>
This commit is contained in:
Damon Kaswell
2022-12-05 08:06:33 -08:00
parent a579b64bc6
commit f278c1bd79
@@ -563,19 +563,19 @@ export class IncrementalIngestionDatabaseManager {
const refs = entities.map(e => stringifyEntityRef(e.entity));
await this.client.transaction(async tx => {
const existingRefs = new Set(
...(
await tx<{ ref: string }>('ingestion_mark_entities')
.select('ref')
.whereIn('ref', refs)
).map(e => e.ref),
);
const existingRefsArray = (
await tx<{ ref: string }>('ingestion_mark_entities')
.select('ref')
.whereIn('ref', refs)
).map(e => e.ref);
const newRefs = refs.filter(e => !existingRefs.has(e));
const existingRefsSet = new Set(existingRefsArray);
const newRefs = refs.filter(e => !existingRefsSet.has(e));
await tx('ingestion_mark_entities')
.update('ingestion_mark_id', markId)
.whereIn('ref', Array.from(existingRefs));
.whereIn('ref', existingRefsArray);
await tx('ingestion_mark_entities').insert(
newRefs.map(ref => ({