message: Bake subquery into the delete clause
diff: @@ -212,7 +212,10 @@ export class TechInsightsDatabase implements TechInsightsStore {
  factRetrieverId: string,
  maxItems: number,
  ) {
  - const deletables = await tx<RawDbFactRow>('facts')
  + const deletionFilterQuery = (subTx: Knex.QueryBuilder<any, unknown[]>) =>
  + subTx
  + .select(['id', 'entity', 'timestamp'])
  + .from('facts')
  .where({ id: factRetrieverId })
  .and.whereIn('entity', db =>
  db.distinct('entity').where({ id: factRetrieverId }),
  @@ -246,9 +249,8 @@ export class TechInsightsDatabase implements TechInsightsStore {
  )
  .whereNull('filterjoin.fid');
  await tx('facts')
  - .whereIn(
  - ['id', 'entity', 'timestamp'],
  - deletables.map(it => [it.id, it.entity, it.timestamp]),
  + .whereIn(['id', 'entity', 'timestamp'], database =>
  + deletionFilterQuery(database),
  )
  .delete();
  }
  