mirror of
https://github.com/immich-app/immich.git
synced 2026-03-07 02:27:23 +03:00
fix: empty and restore over 1,000 items (#12751)
This commit is contained in:
49
server/src/repositories/trash.repository.ts
Normal file
49
server/src/repositories/trash.repository.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { AssetEntity } from 'src/entities/asset.entity';
|
||||
import { AssetStatus } from 'src/enum';
|
||||
import { ITrashRepository } from 'src/interfaces/trash.interface';
|
||||
import { Paginated, paginatedBuilder, PaginationOptions } from 'src/utils/pagination';
|
||||
import { In, IsNull, Not, Repository } from 'typeorm';
|
||||
|
||||
export class TrashRepository implements ITrashRepository {
|
||||
constructor(@InjectRepository(AssetEntity) private assetRepository: Repository<AssetEntity>) {}
|
||||
|
||||
async getDeletedIds(pagination: PaginationOptions): Paginated<string> {
|
||||
const { hasNextPage, items } = await paginatedBuilder(
|
||||
this.assetRepository
|
||||
.createQueryBuilder('asset')
|
||||
.select('asset.id')
|
||||
.where({ status: AssetStatus.DELETED })
|
||||
.withDeleted(),
|
||||
pagination,
|
||||
);
|
||||
|
||||
return {
|
||||
hasNextPage,
|
||||
items: items.map((asset) => asset.id),
|
||||
};
|
||||
}
|
||||
|
||||
async restore(userId: string): Promise<number> {
|
||||
const result = await this.assetRepository.update(
|
||||
{ ownerId: userId, deletedAt: Not(IsNull()) },
|
||||
{ status: AssetStatus.ACTIVE, deletedAt: null },
|
||||
);
|
||||
|
||||
return result.affected || 0;
|
||||
}
|
||||
|
||||
async empty(userId: string): Promise<number> {
|
||||
const result = await this.assetRepository.update(
|
||||
{ ownerId: userId, deletedAt: Not(IsNull()), status: AssetStatus.TRASHED },
|
||||
{ status: AssetStatus.DELETED },
|
||||
);
|
||||
|
||||
return result.affected || 0;
|
||||
}
|
||||
|
||||
async restoreAll(ids: string[]): Promise<number> {
|
||||
const result = await this.assetRepository.update({ id: In(ids) }, { status: AssetStatus.ACTIVE, deletedAt: null });
|
||||
return result.affected ?? 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user