mirror of
https://github.com/immich-app/immich.git
synced 2025-06-01 12:44:17 -04:00
fix: do not select album in time bucket query (#17662)
This commit is contained in:
parent
29b30570bf
commit
8b38f8a58d
@ -2,7 +2,6 @@ import { DeduplicateJoinsPlugin, ExpressionBuilder, Kysely, SelectQueryBuilder,
|
|||||||
import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres';
|
import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres';
|
||||||
import { AssetFace, AssetFile, AssetJobStatus, columns, Exif, Stack, Tag, User } from 'src/database';
|
import { AssetFace, AssetFile, AssetJobStatus, columns, Exif, Stack, Tag, User } from 'src/database';
|
||||||
import { DB } from 'src/db';
|
import { DB } from 'src/db';
|
||||||
import { AlbumEntity } from 'src/entities/album.entity';
|
|
||||||
import { SharedLinkEntity } from 'src/entities/shared-link.entity';
|
import { SharedLinkEntity } from 'src/entities/shared-link.entity';
|
||||||
import { AssetFileType, AssetStatus, AssetType } from 'src/enum';
|
import { AssetFileType, AssetStatus, AssetType } from 'src/enum';
|
||||||
import { TimeBucketSize } from 'src/repositories/asset.repository';
|
import { TimeBucketSize } from 'src/repositories/asset.repository';
|
||||||
@ -45,7 +44,6 @@ export class AssetEntity {
|
|||||||
exifInfo?: Exif;
|
exifInfo?: Exif;
|
||||||
tags?: Tag[];
|
tags?: Tag[];
|
||||||
sharedLinks!: SharedLinkEntity[];
|
sharedLinks!: SharedLinkEntity[];
|
||||||
albums?: AlbumEntity[];
|
|
||||||
faces!: AssetFace[];
|
faces!: AssetFace[];
|
||||||
stackId?: string | null;
|
stackId?: string | null;
|
||||||
stack?: Stack | 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'>) {
|
export function withTags(eb: ExpressionBuilder<DB, 'assets'>) {
|
||||||
return jsonArrayFrom(
|
return jsonArrayFrom(
|
||||||
eb
|
eb
|
||||||
|
@ -9,7 +9,6 @@ import {
|
|||||||
hasPeople,
|
hasPeople,
|
||||||
searchAssetBuilder,
|
searchAssetBuilder,
|
||||||
truncatedDate,
|
truncatedDate,
|
||||||
withAlbums,
|
|
||||||
withExif,
|
withExif,
|
||||||
withFaces,
|
withFaces,
|
||||||
withFacesAndPeople,
|
withFacesAndPeople,
|
||||||
@ -381,16 +380,6 @@ export class AssetRepository {
|
|||||||
await this.db.deleteFrom('assets').where('ownerId', '=', ownerId).execute();
|
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[]> {
|
async getByDeviceIds(ownerId: string, deviceId: string, deviceAssetIds: string[]): Promise<string[]> {
|
||||||
const assets = await this.db
|
const assets = await this.db
|
||||||
.selectFrom('assets')
|
.selectFrom('assets')
|
||||||
@ -760,7 +749,11 @@ export class AssetRepository {
|
|||||||
.selectFrom('assets')
|
.selectFrom('assets')
|
||||||
.selectAll('assets')
|
.selectAll('assets')
|
||||||
.$call(withExif)
|
.$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.personId, (qb) => hasPeople(qb, [options.personId!]))
|
||||||
.$if(!!options.userIds, (qb) => qb.where('assets.ownerId', '=', anyUuid(options.userIds!)))
|
.$if(!!options.userIds, (qb) => qb.where('assets.ownerId', '=', anyUuid(options.userIds!)))
|
||||||
.$if(options.isArchived !== undefined, (qb) => qb.where('assets.isArchived', '=', options.isArchived!))
|
.$if(options.isArchived !== undefined, (qb) => qb.where('assets.isArchived', '=', options.isArchived!))
|
||||||
|
@ -12,7 +12,6 @@ export const newAssetRepositoryMock = (): Mocked<RepositoryInterface<AssetReposi
|
|||||||
getByDayOfYear: vitest.fn(),
|
getByDayOfYear: vitest.fn(),
|
||||||
getByIds: vitest.fn().mockResolvedValue([]),
|
getByIds: vitest.fn().mockResolvedValue([]),
|
||||||
getByIdsWithAllRelations: vitest.fn().mockResolvedValue([]),
|
getByIdsWithAllRelations: vitest.fn().mockResolvedValue([]),
|
||||||
getByAlbumId: vitest.fn(),
|
|
||||||
getByDeviceIds: vitest.fn(),
|
getByDeviceIds: vitest.fn(),
|
||||||
getByUserId: vitest.fn(),
|
getByUserId: vitest.fn(),
|
||||||
getById: vitest.fn(),
|
getById: vitest.fn(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user