use onConflict

Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
Kiss Miklos
2022-07-04 18:35:02 +02:00
parent aa1e84e78a
commit 61aca33a25
@@ -141,24 +141,12 @@ export class DefaultProcessingDatabase implements ProcessingDatabase {
BATCH_SIZE,
);
// Find the top-level location entity that manages the processedEntity
let entityRefToRefresh = sourceEntityRef;
const { entityRefs } = await this.listAncestors(tx, {
entityRef: sourceEntityRef,
});
const locationAncestor = entityRefs.find(ref =>
ref.startsWith('location:'),
);
if (locationAncestor) {
entityRefToRefresh = locationAncestor;
}
// Insert the refresh keys for the processed entity
await Promise.all(
options.refreshKeys.map(k => {
return tx<DbRefreshKeysRow>('refresh_keys')
.insert({
entity_ref: entityRefToRefresh,
entity_ref: sourceEntityRef,
key: k.key,
})
.onConflict(['entity_ref', 'key'])