1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-24 08:52:28 +02:00

refactor(server): remove has asset (#10891)

This commit is contained in:
Jason Rasmussen 2024-07-05 15:10:11 -04:00 committed by GitHub
parent cf88f4b6f8
commit 53d4a5268b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 5 additions and 63 deletions

View File

@ -14,21 +14,10 @@ export interface AlbumInfoOptions {
withAssets: boolean;
}
export interface AlbumAsset {
albumId: string;
assetId: string;
}
export interface AlbumAssets {
albumId: string;
assetIds: string[];
}
export interface IAlbumRepository extends IBulkAsset {
getById(id: string, options: AlbumInfoOptions): Promise<AlbumEntity | null>;
getByIds(ids: string[]): Promise<AlbumEntity[]>;
getByAssetId(ownerId: string, assetId: string): Promise<AlbumEntity[]>;
hasAsset(asset: AlbumAsset): Promise<boolean>;
removeAsset(assetId: string): Promise<void>;
getMetadataForIds(ids: string[]): Promise<AlbumAssetCount[]>;
getInvalidThumbnail(): Promise<string[]>;

View File

@ -585,37 +585,6 @@ WHERE
"albums_assets"."albumsId" = $1
AND "albums_assets"."assetsId" IN ($2)
-- AlbumRepository.hasAsset
SELECT
1 AS "row_exists"
FROM
(
SELECT
1 AS dummy_column
) "dummy_table"
WHERE
EXISTS (
SELECT
1
FROM
"albums" "AlbumEntity"
LEFT JOIN "albums_assets_assets" "AlbumEntity_AlbumEntity__AlbumEntity_assets" ON "AlbumEntity_AlbumEntity__AlbumEntity_assets"."albumsId" = "AlbumEntity"."id"
LEFT JOIN "assets" "AlbumEntity__AlbumEntity_assets" ON "AlbumEntity__AlbumEntity_assets"."id" = "AlbumEntity_AlbumEntity__AlbumEntity_assets"."assetsId"
AND (
"AlbumEntity__AlbumEntity_assets"."deletedAt" IS NULL
)
WHERE
(
(
("AlbumEntity"."id" = $1)
AND ((("AlbumEntity__AlbumEntity_assets"."id" = $2)))
)
)
AND ("AlbumEntity"."deletedAt" IS NULL)
)
LIMIT
1
-- AlbumRepository.addAssetIds
INSERT INTO
"albums_assets_assets" ("albumsId", "assetsId")

View File

@ -3,7 +3,7 @@ import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { Chunked, ChunkedArray, ChunkedSet, DummyValue, GenerateSql } from 'src/decorators';
import { AlbumEntity } from 'src/entities/album.entity';
import { AssetEntity } from 'src/entities/asset.entity';
import { AlbumAsset, AlbumAssetCount, AlbumInfoOptions, IAlbumRepository } from 'src/interfaces/album.interface';
import { AlbumAssetCount, AlbumInfoOptions, IAlbumRepository } from 'src/interfaces/album.interface';
import { Instrumentation } from 'src/utils/instrumentation';
import { DataSource, FindOptionsOrder, FindOptionsRelations, In, IsNull, Not, Repository } from 'typeorm';
@ -253,21 +253,6 @@ export class AlbumRepository implements IAlbumRepository {
return new Set(results.map(({ assetId }) => assetId));
}
@GenerateSql({ params: [{ albumId: DummyValue.UUID, assetId: DummyValue.UUID }] })
hasAsset(asset: AlbumAsset): Promise<boolean> {
return this.repository.exist({
where: {
id: asset.albumId,
assets: {
id: asset.assetId,
},
},
relations: {
assets: true,
},
});
}
@GenerateSql({ params: [DummyValue.UUID, [DummyValue.UUID]] })
async addAssetIds(albumId: string, assetIds: string[]): Promise<void> {
await this.dataSource

View File

@ -270,7 +270,7 @@ describe(AlbumService.name, () => {
accessMock.album.checkOwnerAccess.mockResolvedValue(new Set(['album-4']));
albumMock.getById.mockResolvedValue(albumStub.oneAsset);
albumMock.update.mockResolvedValue(albumStub.oneAsset);
albumMock.hasAsset.mockResolvedValue(false);
albumMock.getAssetIds.mockResolvedValue(new Set());
await expect(
sut.update(authStub.admin, albumStub.oneAsset.id, {
@ -278,7 +278,7 @@ describe(AlbumService.name, () => {
}),
).rejects.toBeInstanceOf(BadRequestException);
expect(albumMock.hasAsset).toHaveBeenCalledWith({ albumId: 'album-4', assetId: 'not-in-album' });
expect(albumMock.getAssetIds).toHaveBeenCalledWith('album-4', ['not-in-album']);
expect(albumMock.update).not.toHaveBeenCalled();
});

View File

@ -146,8 +146,8 @@ export class AlbumService {
const album = await this.findOrFail(id, { withAssets: true });
if (dto.albumThumbnailAssetId) {
const valid = await this.albumRepository.hasAsset({ albumId: id, assetId: dto.albumThumbnailAssetId });
if (!valid) {
const results = await this.albumRepository.getAssetIds(id, [dto.albumThumbnailAssetId]);
if (results.size === 0) {
throw new BadRequestException('Invalid album thumbnail');
}
}

View File

@ -19,7 +19,6 @@ export const newAlbumRepositoryMock = (): Mocked<IAlbumRepository> => {
removeAsset: vitest.fn(),
removeAssetIds: vitest.fn(),
getAssetIds: vitest.fn(),
hasAsset: vitest.fn(),
create: vitest.fn(),
update: vitest.fn(),
delete: vitest.fn(),