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() {
|
async deleteEmptyTags() {
|
||||||
// TODO rewrite as a single statement
|
|
||||||
await this.db.transaction().execute(async (tx) => {
|
await this.db.transaction().execute(async (tx) => {
|
||||||
const result = await tx
|
const result = await tx
|
||||||
.selectFrom('tag')
|
.deleteFrom('tag')
|
||||||
.select('tag.id')
|
.where('id', 'in', (eb) =>
|
||||||
.leftJoin('tag_asset', 'tag.id', 'tag_asset.tagsId')
|
eb
|
||||||
.where('tag_asset.assetsId', 'is', null)
|
.selectFrom('tag')
|
||||||
.execute();
|
.leftJoin('tag_asset', 'tag.id', 'tag_asset.tagsId')
|
||||||
|
.select('tag.id')
|
||||||
|
.where('tag_asset.assetsId', 'is', null),
|
||||||
|
)
|
||||||
|
.executeTakeFirst();
|
||||||
|
|
||||||
const ids = result.map(row => row.id);
|
const deletedRows = Number(result.numDeletedRows);
|
||||||
if (ids.length > 0) {
|
if (deletedRows > 0) {
|
||||||
await this.db.deleteFrom('tag').where('id', 'in', ids).execute();
|
this.logger.log(`Deleted ${deletedRows} empty tags`);
|
||||||
this.logger.log(`Deleted ${ids.length} empty tags`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue