From b6d0c26902c97a5a18063e6bc5ce5d7d61ffe058 Mon Sep 17 00:00:00 2001 From: Damon Kaswell Date: Thu, 17 Nov 2022 13:23:52 -0800 Subject: [PATCH] Use foreign key constraints Signed-off-by: Damon Kaswell --- .../migrations/20221116073152_init.js | 6 +++++ .../src/engine/IncrementalIngestionEngine.ts | 24 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/plugins/incremental-ingestion-backend/migrations/20221116073152_init.js b/plugins/incremental-ingestion-backend/migrations/20221116073152_init.js index 9e05d0a163..edbe041afe 100644 --- a/plugins/incremental-ingestion-backend/migrations/20221116073152_init.js +++ b/plugins/incremental-ingestion-backend/migrations/20221116073152_init.js @@ -111,6 +111,9 @@ exports.up = async function up(knex) { table .uuid('ingestion_id') .notNullable() + .references('id') + .inTable('ingestions') + .onDelete('CASCADE') .comment('The id of the ingestion in which this mark took place'); table @@ -148,6 +151,9 @@ exports.up = async function up(knex) { table .uuid('ingestion_mark_id') .notNullable() + .references('id') + .inTable('ingestion_marks') + .onDelete('CASCADE') .comment( 'Every time a mark happens during an ingestion, there are a list of entities marked.', ); diff --git a/plugins/incremental-ingestion-backend/src/engine/IncrementalIngestionEngine.ts b/plugins/incremental-ingestion-backend/src/engine/IncrementalIngestionEngine.ts index 6d35f2db4b..c370390fd6 100644 --- a/plugins/incremental-ingestion-backend/src/engine/IncrementalIngestionEngine.ts +++ b/plugins/incremental-ingestion-backend/src/engine/IncrementalIngestionEngine.ts @@ -280,12 +280,24 @@ export class IncrementalIngestionEngine implements IterationEngine { }, })) ?? []; - const removed: DeferredEntity[] = done - ? [] - : await this.manager.computeRemoved( - this.options.provider.getProviderName(), - id, - ); + const removed: DeferredEntity[] = []; + + let doComputeRemoved = false; + + if (!done) { + doComputeRemoved = true; + } else { + if (entities && entities.length > 0) { + doComputeRemoved = true; + } + } + + if(doComputeRemoved) { + removed.push(...await this.manager.computeRemoved( + this.options.provider.getProviderName(), + id, + )); + } await this.options.connection.applyMutation({ type: 'delta',