db/events: delete tags during deleteFilters
This commit is contained in:
parent
df17f62ecb
commit
cdffe42cfd
|
@ -157,12 +157,19 @@ async function getFilters<K extends number>(
|
||||||
/** Delete events based on filters from the database. */
|
/** Delete events based on filters from the database. */
|
||||||
function deleteFilters<K extends number>(filters: DittoFilter<K>[]) {
|
function deleteFilters<K extends number>(filters: DittoFilter<K>[]) {
|
||||||
if (!filters.length) return Promise.resolve([]);
|
if (!filters.length) return Promise.resolve([]);
|
||||||
const query = getFiltersQuery(filters);
|
|
||||||
|
|
||||||
return db
|
return db.transaction().execute(async (trx) => {
|
||||||
.deleteFrom('events')
|
const query = getFiltersQuery(filters).clearSelect().select('id');
|
||||||
.where('id', 'in', () => query.clearSelect().select('id'))
|
|
||||||
.execute();
|
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. */
|
/** Get number of events that would be returned by filters. */
|
||||||
|
|
Loading…
Reference in New Issue