mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-12-08 20:29:05 +00:00
fix(server): album add/remove asset performance (#4516)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { AlbumAssetCount, AlbumInfoOptions, IAlbumRepository } from '@app/domain';
|
||||
import { AlbumAsset, AlbumAssetCount, AlbumAssets, AlbumInfoOptions, IAlbumRepository } from '@app/domain';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
|
||||
import { DataSource, FindOptionsOrder, FindOptionsRelations, In, IsNull, Not, Repository } from 'typeorm';
|
||||
@@ -168,16 +168,27 @@ export class AlbumRepository implements IAlbumRepository {
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from('albums_assets_assets')
|
||||
.where('"albums_assets_assets"."assetsId" = :assetId', { assetId })
|
||||
.where('"albums_assets_assets"."assetsId" = :assetId', { assetId });
|
||||
}
|
||||
|
||||
async removeAssets(asset: AlbumAssets): Promise<void> {
|
||||
await this.dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from('albums_assets_assets')
|
||||
.where({
|
||||
albumsId: asset.albumId,
|
||||
assetsId: In(asset.assetIds),
|
||||
})
|
||||
.execute();
|
||||
}
|
||||
|
||||
hasAsset(id: string, assetId: string): Promise<boolean> {
|
||||
hasAsset(asset: AlbumAsset): Promise<boolean> {
|
||||
return this.repository.exist({
|
||||
where: {
|
||||
id,
|
||||
id: asset.albumId,
|
||||
assets: {
|
||||
id: assetId,
|
||||
id: asset.assetId,
|
||||
},
|
||||
},
|
||||
relations: {
|
||||
@@ -186,6 +197,15 @@ export class AlbumRepository implements IAlbumRepository {
|
||||
});
|
||||
}
|
||||
|
||||
async addAssets({ albumId, assetIds }: AlbumAssets): Promise<void> {
|
||||
await this.dataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into('albums_assets_assets', ['albumsId', 'assetsId'])
|
||||
.values(assetIds.map((assetId) => ({ albumsId: albumId, assetsId: assetId })))
|
||||
.execute();
|
||||
}
|
||||
|
||||
async create(album: Partial<AlbumEntity>): Promise<AlbumEntity> {
|
||||
return this.save(album);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user