diff --git a/src/db/events.ts b/src/db/events.ts index b901c10..efb5afc 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -157,12 +157,19 @@ async function getFilters( /** Delete events based on filters from the database. */ function deleteFilters(filters: DittoFilter[]) { if (!filters.length) return Promise.resolve([]); - const query = getFiltersQuery(filters); - return db - .deleteFrom('events') - .where('id', 'in', () => query.clearSelect().select('id')) - .execute(); + return db.transaction().execute(async (trx) => { + const query = getFiltersQuery(filters).clearSelect().select('id'); + + await trx.deleteFrom('tags') + .where('event_id', 'in', () => query) + .where('tag', 'not in', ['d', 'proxy']) + .execute(); + + return trx.deleteFrom('events') + .where('id', 'in', () => query) + .execute(); + }); } /** Get number of events that would be returned by filters. */