Skip to content

High performance self-hosted photo and video management solution.

fix: do not select album in time bucket query (#17662)

Daniel Dietzler8b38f8a58d8a
diff --git a/server/src/entities/asset.entity.ts b/server/src/entities/asset.entity.ts
index b17328f790..cc3a8bb1a0 100644
--- a/server/src/entities/asset.entity.ts
+++ b/server/src/entities/asset.entity.ts
@@ -2,7 +2,6 @@ import { DeduplicateJoinsPlugin, ExpressionBuilder, Kysely, SelectQueryBuilder,
import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres';
import { AssetFace, AssetFile, AssetJobStatus, columns, Exif, Stack, Tag, User } from 'src/database';
import { DB } from 'src/db';
-import { AlbumEntity } from 'src/entities/album.entity';
import { SharedLinkEntity } from 'src/entities/shared-link.entity';
import { AssetFileType, AssetStatus, AssetType } from 'src/enum';
import { TimeBucketSize } from 'src/repositories/asset.repository';
@@ -45,7 +44,6 @@ export class AssetEntity {
exifInfo?: Exif;
tags?: Tag[];
sharedLinks!: SharedLinkEntity[];
- albums?: AlbumEntity[];
faces!: AssetFace[];
stackId?: string | null;
stack?: Stack | null;
@@ -158,34 +156,6 @@ export function withLibrary(eb: ExpressionBuilder<DB, 'assets'>) {
);
}
-export function withAlbums<O>(qb: SelectQueryBuilder<DB, 'assets', O>, { albumId }: { albumId?: string }) {
- return qb
- .select((eb) =>
- jsonArrayFrom(
- eb
- .selectFrom('albums')
- .selectAll('albums')
- .innerJoin('albums_assets_assets', (join) =>
- join
- .onRef('albums.id', '=', 'albums_assets_assets.albumsId')
- .onRef('assets.id', '=', 'albums_assets_assets.assetsId'),
- )
- .whereRef('albums.id', '=', 'albums_assets_assets.albumsId')
- .$if(!!albumId, (qb) => qb.where('albums.id', '=', asUuid(albumId!))),
- ).as('albums'),
- )
- .$if(!!albumId, (qb) =>
- qb.where((eb) =>
- eb.exists((eb) =>
- eb
- .selectFrom('albums_assets_assets')
- .whereRef('albums_assets_assets.assetsId', '=', 'assets.id')
- .where('albums_assets_assets.albumsId', '=', asUuid(albumId!)),
- ),
- ),
- );
-}
-
export function withTags(eb: ExpressionBuilder<DB, 'assets'>) {
return jsonArrayFrom(
eb
diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts
index 9c0a4b1fad..52c390c162 100644
--- a/server/src/repositories/asset.repository.ts
+++ b/server/src/repositories/asset.repository.ts
@@ -9,7 +9,6 @@ import {
hasPeople,
searchAssetBuilder,
truncatedDate,
- withAlbums,
withExif,
withFaces,
withFacesAndPeople,
@@ -381,16 +380,6 @@ export class AssetRepository {
await this.db.deleteFrom('assets').where('ownerId', '=', ownerId).execute();
}
- async getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated<AssetEntity> {
- const items = await withAlbums(this.db.selectFrom('assets'), { albumId })
- .selectAll('assets')
- .where('deletedAt', 'is', null)
- .orderBy('fileCreatedAt', 'desc')
- .execute();
-
- return paginationHelper(items as any as AssetEntity[], pagination.take);
- }
-
async getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<string[]> {
const assets = await this.db
.selectFrom('assets')
@@ -760,7 +749,11 @@ export class AssetRepository {
.selectFrom('assets')
.selectAll('assets')
.$call(withExif)
- .$if(!!options.albumId, (qb) => withAlbums(qb, { albumId: options.albumId }))
+ .$if(!!options.albumId, (qb) =>
+ qb
+ .innerJoin('albums_assets_assets', 'albums_assets_assets.assetsId', 'assets.id')
+ .where('albums_assets_assets.albumsId', '=', options.albumId!),
+ )
.$if(!!options.personId, (qb) => hasPeople(qb, [options.personId!]))
.$if(!!options.userIds, (qb) => qb.where('assets.ownerId', '=', anyUuid(options.userIds!)))
.$if(options.isArchived !== undefined, (qb) => qb.where('assets.isArchived', '=', options.isArchived!))
diff --git a/server/test/repositories/asset.repository.mock.ts b/server/test/repositories/asset.repository.mock.ts
index f33b487888..2418b6aa64 100644
--- a/server/test/repositories/asset.repository.mock.ts
+++ b/server/test/repositories/asset.repository.mock.ts
@@ -12,7 +12,6 @@ export const newAssetRepositoryMock = (): Mocked<RepositoryInterface<AssetReposi
getByDayOfYear: vitest.fn(),
getByIds: vitest.fn().mockResolvedValue([]),
getByIdsWithAllRelations: vitest.fn().mockResolvedValue([]),
- getByAlbumId: vitest.fn(),
getByDeviceIds: vitest.fn(),
getByUserId: vitest.fn(),
getById: vitest.fn(),