mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
rewrite as a single statement
This commit is contained in:
parent
0bf848b1e7
commit
6075f5313e
1 changed files with 12 additions and 10 deletions
|
|
@ -163,19 +163,21 @@ export class TagRepository {
|
|||
}
|
||||
|
||||
async deleteEmptyTags() {
|
||||
// TODO rewrite as a single statement
|
||||
await this.db.transaction().execute(async (tx) => {
|
||||
const result = await tx
|
||||
.deleteFrom('tag')
|
||||
.where('id', 'in', (eb) =>
|
||||
eb
|
||||
.selectFrom('tag')
|
||||
.select('tag.id')
|
||||
.leftJoin('tag_asset', 'tag.id', 'tag_asset.tagsId')
|
||||
.where('tag_asset.assetsId', 'is', null)
|
||||
.execute();
|
||||
.select('tag.id')
|
||||
.where('tag_asset.assetsId', 'is', null),
|
||||
)
|
||||
.executeTakeFirst();
|
||||
|
||||
const ids = result.map(row => row.id);
|
||||
if (ids.length > 0) {
|
||||
await this.db.deleteFrom('tag').where('id', 'in', ids).execute();
|
||||
this.logger.log(`Deleted ${ids.length} empty tags`);
|
||||
const deletedRows = Number(result.numDeletedRows);
|
||||
if (deletedRows > 0) {
|
||||
this.logger.log(`Deleted ${deletedRows} empty tags`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue