From 1b48e2a176c08ac4c4402cb38651cbe3f5db77a7 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 20:56:29 -0500 Subject: [PATCH 01/15] faster query --- .../domain/repositories/asset.repository.ts | 1 + .../domain/repositories/search.repository.ts | 8 ++++--- .../src/immich/api-v1/asset/asset.service.ts | 7 ++++-- .../infra/repositories/asset.repository.ts | 23 +++++++++++++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/server/src/domain/repositories/asset.repository.ts b/server/src/domain/repositories/asset.repository.ts index a8433c7680212..b401286388de8 100644 --- a/server/src/domain/repositories/asset.repository.ts +++ b/server/src/domain/repositories/asset.repository.ts @@ -133,6 +133,7 @@ export interface IAssetRepository { getByLibraryIdAndOriginalPath(libraryId: string, originalPath: string): Promise; deleteAll(ownerId: string): Promise; getAll(pagination: PaginationOptions, options?: AssetSearchOptions): Paginated; + getAllByFileCreationDate(pagination: PaginationOptions, options?: AssetSearchOptions): Paginated; getAllByDeviceId(userId: string, deviceId: string): Promise; updateAll(ids: string[], options: Partial): Promise; save(asset: Pick & Partial): Promise; diff --git a/server/src/domain/repositories/search.repository.ts b/server/src/domain/repositories/search.repository.ts index 35ead53dbc3e4..20d46a5d3b6c9 100644 --- a/server/src/domain/repositories/search.repository.ts +++ b/server/src/domain/repositories/search.repository.ts @@ -69,7 +69,6 @@ export interface SearchAssetIDOptions { export interface SearchUserIdOptions { deviceId?: string; libraryId?: string; - ownerId?: string; userIds?: string[]; } @@ -147,8 +146,7 @@ export interface SearchPaginationOptions { size: number; } -export type AssetSearchOptions = SearchDateOptions & - SearchIdOptions & +type BaseAssetSearchOptions = SearchIdOptions & SearchExifOptions & SearchOrderOptions & SearchPathOptions & @@ -157,6 +155,10 @@ export type AssetSearchOptions = SearchDateOptions & SearchUserIdOptions & SearchPeopleOptions; +export type AssetSearchOptions = BaseAssetSearchOptions & SearchRelationOptions; + +export type AssetSearchOneToOneRelationOptions = BaseAssetSearchOptions & SearchOneToOneRelationOptions; + export type AssetSearchBuilderOptions = Omit; export type SmartSearchOptions = SearchDateOptions & diff --git a/server/src/immich/api-v1/asset/asset.service.ts b/server/src/immich/api-v1/asset/asset.service.ts index f438e55e9c30e..47418e35331d4 100644 --- a/server/src/immich/api-v1/asset/asset.service.ts +++ b/server/src/immich/api-v1/asset/asset.service.ts @@ -114,8 +114,11 @@ export class AssetService { public async getAllAssets(auth: AuthDto, dto: AssetSearchDto): Promise { const userId = dto.userId || auth.user.id; await this.access.requirePermission(auth, Permission.TIMELINE_READ, userId); - const assets = await this.assetRepositoryV1.getAllByUserId(userId, dto); - return assets.map((asset) => mapAsset(asset, { withStack: true })); + const assets = await this.assetRepository.getAllByFileCreationDate( + { take: dto.take ?? 1000, skip: dto.skip }, + { ...dto, withDeleted: true, orderDirection: 'DESC' }, + ); + return assets.items.map((asset) => mapAsset(asset)); } async serveThumbnail(auth: AuthDto, assetId: string, dto: GetAssetThumbnailDto): Promise { diff --git a/server/src/infra/repositories/asset.repository.ts b/server/src/infra/repositories/asset.repository.ts index b60f7285716ec..106936403cc31 100644 --- a/server/src/infra/repositories/asset.repository.ts +++ b/server/src/infra/repositories/asset.repository.ts @@ -2,6 +2,7 @@ import { AssetBuilderOptions, AssetCreate, AssetExploreFieldOptions, + AssetSearchOneToOneRelationOptions, AssetSearchOptions, AssetStats, AssetStatsOptions, @@ -175,8 +176,12 @@ export class AssetRepository implements IAssetRepository { }); } - getByUserId(pagination: PaginationOptions, userId: string, options: AssetSearchOptions = {}): Paginated { - return this.getAll(pagination, { ...options, ownerId: userId }); + getByUserId( + pagination: PaginationOptions, + userId: string, + options: Omit = {}, + ): Paginated { + return this.getAll(pagination, { ...options, userIds: [userId] }); } @GenerateSql({ params: [[DummyValue.UUID]] }) @@ -205,6 +210,20 @@ export class AssetRepository implements IAssetRepository { }); } + getAllByFileCreationDate( + pagination: PaginationOptions, + options: AssetSearchOneToOneRelationOptions = {}, + ): Paginated { + let builder = this.repository.createQueryBuilder('asset'); + builder = searchAssetBuilder(builder, options); + builder.orderBy('asset.fileCreatedAt', options.orderDirection ?? 'DESC'); + return paginatedBuilder(builder, { + mode: PaginationMode.LIMIT_OFFSET, + skip: pagination.skip, + take: pagination.take, + }); + } + /** * Get assets by device's Id on the database * @param ownerId From 7b3165504b534e5eb85e1a5b6f363b829096af44 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 22:40:27 -0500 Subject: [PATCH 02/15] add index --- server/src/domain/repositories/search.repository.ts | 3 ++- server/src/infra/entities/asset.entity.ts | 1 + .../1708227417898-AddFileCreatedAtIndex.ts | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 server/src/infra/migrations/1708227417898-AddFileCreatedAtIndex.ts diff --git a/server/src/domain/repositories/search.repository.ts b/server/src/domain/repositories/search.repository.ts index 20d46a5d3b6c9..c3656850d0dc8 100644 --- a/server/src/domain/repositories/search.repository.ts +++ b/server/src/domain/repositories/search.repository.ts @@ -146,7 +146,8 @@ export interface SearchPaginationOptions { size: number; } -type BaseAssetSearchOptions = SearchIdOptions & +type BaseAssetSearchOptions = SearchDateOptions & + SearchIdOptions & SearchExifOptions & SearchOrderOptions & SearchPathOptions & diff --git a/server/src/infra/entities/asset.entity.ts b/server/src/infra/entities/asset.entity.ts index 10973be74eea1..373271158177c 100644 --- a/server/src/infra/entities/asset.entity.ts +++ b/server/src/infra/entities/asset.entity.ts @@ -85,6 +85,7 @@ export class AssetEntity { @DeleteDateColumn({ type: 'timestamptz', nullable: true }) deletedAt!: Date | null; + @Index('idx_asset_file_created_at') @Column({ type: 'timestamptz' }) fileCreatedAt!: Date; diff --git a/server/src/infra/migrations/1708227417898-AddFileCreatedAtIndex.ts b/server/src/infra/migrations/1708227417898-AddFileCreatedAtIndex.ts new file mode 100644 index 0000000000000..f7ca40cd4633a --- /dev/null +++ b/server/src/infra/migrations/1708227417898-AddFileCreatedAtIndex.ts @@ -0,0 +1,12 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddFileCreatedAtIndex1708227417898 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE INDEX idx_asset_file_created_at ON assets ("fileCreatedAt")`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX idx_asset_file_created_at`); + } +} From 9944498fc0b3da61534717e4faf87f971efa3175 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:04:41 -0500 Subject: [PATCH 03/15] remove legacy code --- .../immich/api-v1/asset/asset-repository.ts | 28 ------------------- .../immich/api-v1/asset/asset.service.spec.ts | 1 - 2 files changed, 29 deletions(-) diff --git a/server/src/immich/api-v1/asset/asset-repository.ts b/server/src/immich/api-v1/asset/asset-repository.ts index 7d55fa790e385..0ff117d0dfb3d 100644 --- a/server/src/immich/api-v1/asset/asset-repository.ts +++ b/server/src/immich/api-v1/asset/asset-repository.ts @@ -21,7 +21,6 @@ export interface AssetOwnerCheck extends AssetCheck { export interface IAssetRepositoryV1 { get(id: string): Promise; - getAllByUserId(userId: string, dto: AssetSearchDto): Promise; getLocationsByUserId(userId: string): Promise; getDetectedObjectsByUserId(userId: string): Promise; getSearchPropertiesByUserId(userId: string): Promise; @@ -89,33 +88,6 @@ export class AssetRepositoryV1 implements IAssetRepositoryV1 { ); } - /** - * Get all assets belong to the user on the database - * @param ownerId - */ - getAllByUserId(ownerId: string, dto: AssetSearchDto): Promise { - return this.assetRepository.find({ - where: { - ownerId, - isVisible: true, - isFavorite: dto.isFavorite, - isArchived: dto.isArchived, - updatedAt: OptionalBetween(dto.updatedAfter, dto.updatedBefore), - }, - relations: { - exifInfo: true, - tags: true, - stack: { assets: true }, - }, - skip: dto.skip || 0, - take: dto.take, - order: { - fileCreatedAt: 'DESC', - }, - withDeleted: true, - }); - } - get(id: string): Promise { return this.assetRepository.findOne({ where: { id }, diff --git a/server/src/immich/api-v1/asset/asset.service.spec.ts b/server/src/immich/api-v1/asset/asset.service.spec.ts index 9f0aa371e8635..48354d440ec60 100644 --- a/server/src/immich/api-v1/asset/asset.service.spec.ts +++ b/server/src/immich/api-v1/asset/asset.service.spec.ts @@ -77,7 +77,6 @@ describe('AssetService', () => { beforeEach(() => { assetRepositoryMockV1 = { get: jest.fn(), - getAllByUserId: jest.fn(), getDetectedObjectsByUserId: jest.fn(), getLocationsByUserId: jest.fn(), getSearchPropertiesByUserId: jest.fn(), From 1ad52b095255ed1b4cb83e4057213f31eb77130f Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:13:08 -0500 Subject: [PATCH 04/15] update mock --- server/test/repositories/asset.repository.mock.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/server/test/repositories/asset.repository.mock.ts b/server/test/repositories/asset.repository.mock.ts index 1c98b78c9edd7..0be384b3aeff1 100644 --- a/server/test/repositories/asset.repository.mock.ts +++ b/server/test/repositories/asset.repository.mock.ts @@ -18,6 +18,7 @@ export const newAssetRepositoryMock = (): jest.Mocked => { getFirstAssetForAlbumId: jest.fn(), getLastUpdatedAssetForAlbumId: jest.fn(), getAll: jest.fn().mockResolvedValue({ items: [], hasNextPage: false }), + getAllByFileCreationDate: jest.fn(), getAllByDeviceId: jest.fn(), updateAll: jest.fn(), getByLibraryId: jest.fn(), From 9c030c13dea686eda163bf673d5a67b204dcab16 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:17:56 -0500 Subject: [PATCH 05/15] remove unused imports --- server/src/immich/api-v1/asset/asset-repository.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/src/immich/api-v1/asset/asset-repository.ts b/server/src/immich/api-v1/asset/asset-repository.ts index 0ff117d0dfb3d..db3fdc4e5d2b5 100644 --- a/server/src/immich/api-v1/asset/asset-repository.ts +++ b/server/src/immich/api-v1/asset/asset-repository.ts @@ -1,10 +1,8 @@ import { AssetEntity, ExifEntity } from '@app/infra/entities'; -import { OptionalBetween } from '@app/infra/infra.utils'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { In } from 'typeorm/find-options/operator/In.js'; import { Repository } from 'typeorm/repository/Repository.js'; -import { AssetSearchDto } from './dto/asset-search.dto'; import { CheckExistingAssetsDto } from './dto/check-existing-assets.dto'; import { SearchPropertiesDto } from './dto/search-properties.dto'; import { CuratedLocationsResponseDto } from './response-dto/curated-locations-response.dto'; From 6fdfefda3831e8b6b37973f06b763ffed92847b1 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:21:30 -0500 Subject: [PATCH 06/15] add relations --- server/src/immich/api-v1/asset/asset-repository.ts | 1 - server/src/immich/api-v1/asset/asset.service.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/immich/api-v1/asset/asset-repository.ts b/server/src/immich/api-v1/asset/asset-repository.ts index db3fdc4e5d2b5..b10ab6d0e4992 100644 --- a/server/src/immich/api-v1/asset/asset-repository.ts +++ b/server/src/immich/api-v1/asset/asset-repository.ts @@ -33,7 +33,6 @@ export const IAssetRepositoryV1 = 'IAssetRepositoryV1'; export class AssetRepositoryV1 implements IAssetRepositoryV1 { constructor( @InjectRepository(AssetEntity) private assetRepository: Repository, - @InjectRepository(ExifEntity) private exifRepository: Repository, ) {} getSearchPropertiesByUserId(userId: string): Promise { diff --git a/server/src/immich/api-v1/asset/asset.service.ts b/server/src/immich/api-v1/asset/asset.service.ts index 47418e35331d4..5e1b37729c68f 100644 --- a/server/src/immich/api-v1/asset/asset.service.ts +++ b/server/src/immich/api-v1/asset/asset.service.ts @@ -116,7 +116,7 @@ export class AssetService { await this.access.requirePermission(auth, Permission.TIMELINE_READ, userId); const assets = await this.assetRepository.getAllByFileCreationDate( { take: dto.take ?? 1000, skip: dto.skip }, - { ...dto, withDeleted: true, orderDirection: 'DESC' }, + { ...dto, withDeleted: true, orderDirection: 'DESC', withExif: true, withStacked: true }, ); return assets.items.map((asset) => mapAsset(asset)); } From c1bac7112d20a694ec6ccdb2672bce2e5a9e5a8a Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:22:28 -0500 Subject: [PATCH 07/15] add stack --- server/src/immich/api-v1/asset/asset.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/immich/api-v1/asset/asset.service.ts b/server/src/immich/api-v1/asset/asset.service.ts index 5e1b37729c68f..8f942e8b8939a 100644 --- a/server/src/immich/api-v1/asset/asset.service.ts +++ b/server/src/immich/api-v1/asset/asset.service.ts @@ -118,7 +118,7 @@ export class AssetService { { take: dto.take ?? 1000, skip: dto.skip }, { ...dto, withDeleted: true, orderDirection: 'DESC', withExif: true, withStacked: true }, ); - return assets.items.map((asset) => mapAsset(asset)); + return assets.items.map((asset) => mapAsset(asset, { withStack: true })); } async serveThumbnail(auth: AuthDto, assetId: string, dto: GetAssetThumbnailDto): Promise { From 6ff9c9a812409fb0c80b9a4bc0adefbba86e87a4 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:30:31 -0500 Subject: [PATCH 08/15] formatting --- server/src/immich/api-v1/asset/asset-repository.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/src/immich/api-v1/asset/asset-repository.ts b/server/src/immich/api-v1/asset/asset-repository.ts index b10ab6d0e4992..efd40ba3251d9 100644 --- a/server/src/immich/api-v1/asset/asset-repository.ts +++ b/server/src/immich/api-v1/asset/asset-repository.ts @@ -31,9 +31,7 @@ export const IAssetRepositoryV1 = 'IAssetRepositoryV1'; @Injectable() export class AssetRepositoryV1 implements IAssetRepositoryV1 { - constructor( - @InjectRepository(AssetEntity) private assetRepository: Repository, - ) {} + constructor(@InjectRepository(AssetEntity) private assetRepository: Repository) {} getSearchPropertiesByUserId(userId: string): Promise { return this.assetRepository From fdd52d6f7ff3932cef4debc4396a1e31d12cf737 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:31:45 -0500 Subject: [PATCH 09/15] remove stack relation --- server/src/immich/api-v1/asset/asset.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/immich/api-v1/asset/asset.service.ts b/server/src/immich/api-v1/asset/asset.service.ts index 8f942e8b8939a..043383bc56e7b 100644 --- a/server/src/immich/api-v1/asset/asset.service.ts +++ b/server/src/immich/api-v1/asset/asset.service.ts @@ -116,9 +116,9 @@ export class AssetService { await this.access.requirePermission(auth, Permission.TIMELINE_READ, userId); const assets = await this.assetRepository.getAllByFileCreationDate( { take: dto.take ?? 1000, skip: dto.skip }, - { ...dto, withDeleted: true, orderDirection: 'DESC', withExif: true, withStacked: true }, + { ...dto, withDeleted: true, orderDirection: 'DESC', withExif: true }, ); - return assets.items.map((asset) => mapAsset(asset, { withStack: true })); + return assets.items.map((asset) => mapAsset(asset)); } async serveThumbnail(auth: AuthDto, assetId: string, dto: GetAssetThumbnailDto): Promise { From a36eba8d74abae08bb4557a7e121f64279350352 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:38:10 -0500 Subject: [PATCH 10/15] remove unused import --- server/src/immich/api-v1/asset/asset-repository.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/immich/api-v1/asset/asset-repository.ts b/server/src/immich/api-v1/asset/asset-repository.ts index efd40ba3251d9..2f54db27d0cf1 100644 --- a/server/src/immich/api-v1/asset/asset-repository.ts +++ b/server/src/immich/api-v1/asset/asset-repository.ts @@ -1,4 +1,4 @@ -import { AssetEntity, ExifEntity } from '@app/infra/entities'; +import { AssetEntity } from '@app/infra/entities'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { In } from 'typeorm/find-options/operator/In.js'; From 7ebddb6640d8891b68c35ebe21bd9acc75cf4ed3 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:50:42 -0500 Subject: [PATCH 11/15] increase chunk size --- mobile/lib/shared/services/asset.service.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/lib/shared/services/asset.service.dart b/mobile/lib/shared/services/asset.service.dart index 48f8c635245c5..64a0f28ab7d3f 100644 --- a/mobile/lib/shared/services/asset.service.dart +++ b/mobile/lib/shared/services/asset.service.dart @@ -63,7 +63,7 @@ class AssetService { /// Returns `null` if the server state did not change, else list of assets Future?> _getRemoteAssets(User user) async { - const int chunkSize = 5000; + const int chunkSize = 10000; try { final DateTime now = DateTime.now().toUtc(); final List allAssets = []; From 95c64fe6cc08a15ed7cf0dce80efcb035a0bb39f Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:01:57 -0500 Subject: [PATCH 12/15] generate sql --- .../src/immich/api-v1/asset/asset.service.ts | 2 +- .../infra/repositories/asset.repository.ts | 9 ++++ server/src/infra/sql/asset.repository.sql | 49 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/server/src/immich/api-v1/asset/asset.service.ts b/server/src/immich/api-v1/asset/asset.service.ts index 043383bc56e7b..58f800f08cce8 100644 --- a/server/src/immich/api-v1/asset/asset.service.ts +++ b/server/src/immich/api-v1/asset/asset.service.ts @@ -116,7 +116,7 @@ export class AssetService { await this.access.requirePermission(auth, Permission.TIMELINE_READ, userId); const assets = await this.assetRepository.getAllByFileCreationDate( { take: dto.take ?? 1000, skip: dto.skip }, - { ...dto, withDeleted: true, orderDirection: 'DESC', withExif: true }, + { ...dto, userIds: [userId], withDeleted: true, orderDirection: 'DESC', withExif: true }, ); return assets.items.map((asset) => mapAsset(asset)); } diff --git a/server/src/infra/repositories/asset.repository.ts b/server/src/infra/repositories/asset.repository.ts index 106936403cc31..19e497ecb6578 100644 --- a/server/src/infra/repositories/asset.repository.ts +++ b/server/src/infra/repositories/asset.repository.ts @@ -210,6 +210,15 @@ export class AssetRepository implements IAssetRepository { }); } + @GenerateSql({ + params: [ + { skip: 20000, take: 10000 }, + { + takenBefore: DummyValue.DATE, + userIds: [DummyValue.UUID], + }, + ], + }) getAllByFileCreationDate( pagination: PaginationOptions, options: AssetSearchOneToOneRelationOptions = {}, diff --git a/server/src/infra/sql/asset.repository.sql b/server/src/infra/sql/asset.repository.sql index 88f17eb9205f6..d971129e75106 100644 --- a/server/src/infra/sql/asset.repository.sql +++ b/server/src/infra/sql/asset.repository.sql @@ -395,6 +395,55 @@ ORDER BY LIMIT 1 +-- AssetRepository.getAllByFileCreationDate +SELECT + "asset"."id" AS "asset_id", + "asset"."deviceAssetId" AS "asset_deviceAssetId", + "asset"."ownerId" AS "asset_ownerId", + "asset"."libraryId" AS "asset_libraryId", + "asset"."deviceId" AS "asset_deviceId", + "asset"."type" AS "asset_type", + "asset"."originalPath" AS "asset_originalPath", + "asset"."resizePath" AS "asset_resizePath", + "asset"."webpPath" AS "asset_webpPath", + "asset"."thumbhash" AS "asset_thumbhash", + "asset"."encodedVideoPath" AS "asset_encodedVideoPath", + "asset"."createdAt" AS "asset_createdAt", + "asset"."updatedAt" AS "asset_updatedAt", + "asset"."deletedAt" AS "asset_deletedAt", + "asset"."fileCreatedAt" AS "asset_fileCreatedAt", + "asset"."localDateTime" AS "asset_localDateTime", + "asset"."fileModifiedAt" AS "asset_fileModifiedAt", + "asset"."isFavorite" AS "asset_isFavorite", + "asset"."isArchived" AS "asset_isArchived", + "asset"."isExternal" AS "asset_isExternal", + "asset"."isReadOnly" AS "asset_isReadOnly", + "asset"."isOffline" AS "asset_isOffline", + "asset"."checksum" AS "asset_checksum", + "asset"."duration" AS "asset_duration", + "asset"."isVisible" AS "asset_isVisible", + "asset"."livePhotoVideoId" AS "asset_livePhotoVideoId", + "asset"."originalFileName" AS "asset_originalFileName", + "asset"."sidecarPath" AS "asset_sidecarPath", + "asset"."stackId" AS "asset_stackId" +FROM + "assets" "asset" +WHERE + ( + "asset"."fileCreatedAt" <= $1 + AND 1 = 1 + AND "asset"."ownerId" IN ($2) + AND 1 = 1 + AND 1 = 1 + ) + AND ("asset"."deletedAt" IS NULL) +ORDER BY + "asset"."fileCreatedAt" DESC +LIMIT + 10001 +OFFSET + 20000 + -- AssetRepository.getAllByDeviceId SELECT "AssetEntity"."deviceAssetId" AS "AssetEntity_deviceAssetId", From 231805d240fb20712197a7e4ffd7a07a0f1dc473 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sun, 18 Feb 2024 00:27:32 -0500 Subject: [PATCH 13/15] linting --- server/src/infra/repositories/asset.repository.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/infra/repositories/asset.repository.ts b/server/src/infra/repositories/asset.repository.ts index 19e497ecb6578..a31ee2ad44539 100644 --- a/server/src/infra/repositories/asset.repository.ts +++ b/server/src/infra/repositories/asset.repository.ts @@ -212,7 +212,7 @@ export class AssetRepository implements IAssetRepository { @GenerateSql({ params: [ - { skip: 20000, take: 10000 }, + { skip: 20_000, take: 10_000 }, { takenBefore: DummyValue.DATE, userIds: [DummyValue.UUID], From aa61d53ec6434846ef98c177b6a3c91c40f5bc8c Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sun, 18 Feb 2024 01:09:32 -0500 Subject: [PATCH 14/15] fix typing --- server/src/domain/repositories/asset.repository.ts | 4 ++-- server/src/domain/repositories/search.repository.ts | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/domain/repositories/asset.repository.ts b/server/src/domain/repositories/asset.repository.ts index b401286388de8..820b6d1a6ca5b 100644 --- a/server/src/domain/repositories/asset.repository.ts +++ b/server/src/domain/repositories/asset.repository.ts @@ -1,4 +1,4 @@ -import { AssetSearchOptions, SearchExploreItem } from '@app/domain'; +import { AssetSearchOneToOneRelationOptions, AssetSearchOptions, SearchExploreItem } from '@app/domain'; import { AssetEntity, AssetJobStatusEntity, AssetType, ExifEntity } from '@app/infra/entities'; import { FindOptionsRelations, FindOptionsSelect } from 'typeorm'; import { Paginated, PaginationOptions } from '../domain.util'; @@ -133,7 +133,7 @@ export interface IAssetRepository { getByLibraryIdAndOriginalPath(libraryId: string, originalPath: string): Promise; deleteAll(ownerId: string): Promise; getAll(pagination: PaginationOptions, options?: AssetSearchOptions): Paginated; - getAllByFileCreationDate(pagination: PaginationOptions, options?: AssetSearchOptions): Paginated; + getAllByFileCreationDate(pagination: PaginationOptions, options?: AssetSearchOneToOneRelationOptions): Paginated; getAllByDeviceId(userId: string, deviceId: string): Promise; updateAll(ids: string[], options: Partial): Promise; save(asset: Pick & Partial): Promise; diff --git a/server/src/domain/repositories/search.repository.ts b/server/src/domain/repositories/search.repository.ts index c3656850d0dc8..7183e9e3fe269 100644 --- a/server/src/domain/repositories/search.repository.ts +++ b/server/src/domain/repositories/search.repository.ts @@ -151,7 +151,6 @@ type BaseAssetSearchOptions = SearchDateOptions & SearchExifOptions & SearchOrderOptions & SearchPathOptions & - SearchRelationOptions & SearchStatusOptions & SearchUserIdOptions & SearchPeopleOptions; From cb67b3f96c3c5905e401b7c3b6cf523a2732fe57 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sun, 18 Feb 2024 01:15:33 -0500 Subject: [PATCH 15/15] formatting --- server/src/domain/repositories/asset.repository.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/domain/repositories/asset.repository.ts b/server/src/domain/repositories/asset.repository.ts index 820b6d1a6ca5b..7a2941ab9d74e 100644 --- a/server/src/domain/repositories/asset.repository.ts +++ b/server/src/domain/repositories/asset.repository.ts @@ -133,7 +133,10 @@ export interface IAssetRepository { getByLibraryIdAndOriginalPath(libraryId: string, originalPath: string): Promise; deleteAll(ownerId: string): Promise; getAll(pagination: PaginationOptions, options?: AssetSearchOptions): Paginated; - getAllByFileCreationDate(pagination: PaginationOptions, options?: AssetSearchOneToOneRelationOptions): Paginated; + getAllByFileCreationDate( + pagination: PaginationOptions, + options?: AssetSearchOneToOneRelationOptions, + ): Paginated; getAllByDeviceId(userId: string, deviceId: string): Promise; updateAll(ids: string[], options: Partial): Promise; save(asset: Pick & Partial): Promise;