Skip to content

Commit c7914c2

Browse files
committed
refactor(server): AssetRepository.deleteFiles with Kysely
1 parent 4dff398 commit c7914c2

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

server/src/interfaces/asset.interface.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Insertable, Updateable } from 'kysely';
1+
import { Insertable, Selectable, Updateable } from 'kysely';
22
import { AssetFiles, AssetJobStatus, Assets, Exif } from 'src/db';
33
import { AssetEntity } from 'src/entities/asset.entity';
44
import { AssetFileType, AssetOrder, AssetStatus, AssetType } from 'src/enum';
@@ -156,7 +156,6 @@ export interface IAssetRepository {
156156
update(asset: Updateable<Assets> & { id: string }): Promise<AssetEntity>;
157157
remove(asset: AssetEntity): Promise<void>;
158158
findLivePhotoMatch(options: LivePhotoSearchOptions): Promise<AssetEntity | undefined>;
159-
removeAssetFile(path: string): Promise<void>;
160159
getStatistics(ownerId: string, options: AssetStatsOptions): Promise<AssetStats>;
161160
getTimeBuckets(options: TimeBucketOptions): Promise<TimeBucketItem[]>;
162161
getTimeBucket(timeBucket: string, options: TimeBucketOptions): Promise<AssetEntity[]>;
@@ -168,5 +167,5 @@ export interface IAssetRepository {
168167
getChangedDeltaSync(options: AssetDeltaSyncOptions): Promise<AssetEntity[]>;
169168
upsertFile(options: Insertable<AssetFiles>): Promise<void>;
170169
upsertFiles(options: Insertable<AssetFiles>[]): Promise<void>;
171-
deleteFiles(assetIds: string | string[]): Promise<void>;
170+
deleteFiles(options: Selectable<AssetFiles>[]): Promise<void>;
172171
}

server/src/repositories/asset.repository.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable } from '@nestjs/common';
2-
import { Insertable, Kysely, Updateable, sql } from 'kysely';
2+
import { Insertable, Kysely, Selectable, Updateable, sql } from 'kysely';
33
import { isEmpty, isUndefined, omitBy } from 'lodash';
44
import { InjectKysely } from 'nestjs-kysely';
55
import { ASSET_FILE_CONFLICT_KEYS, EXIF_CONFLICT_KEYS, JOB_STATUS_CONFLICT_KEYS } from 'src/constants';
@@ -832,8 +832,14 @@ export class AssetRepository implements IAssetRepository {
832832
.execute();
833833
}
834834

835-
@GenerateSql({ params: [[DummyValue.UUID, DummyValue.UUID]] })
836-
async deleteFiles(assetIds: string | string[]): Promise<void> {
837-
await this.fileRepository.delete(assetIds);
835+
async deleteFiles(files: Pick<Selectable<AssetFiles>, 'id'>[]): Promise<void> {
836+
if (files.length === 0) {
837+
return;
838+
}
839+
840+
await this.db
841+
.deleteFrom('asset_files')
842+
.where('id', '=', anyUuid(files.map((file) => file.id)))
843+
.execute();
838844
}
839845
}

server/src/repositories/media.repository.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
GenerateThumbhashOptions,
1515
GenerateThumbnailOptions,
1616
ImageDimensions,
17-
IMediaRepository,
1817
ProbeOptions,
1918
TranscodeCommand,
2019
VideoInfo,

server/src/services/media.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export class MediaService extends BaseService {
205205
pathsToDelete.push(fullsizeFile.path);
206206
if (!generated.fullsizePath) {
207207
// did not generate a new fullsize image, delete the existing record
208-
await this.assetRepository.deleteFiles(fullsizeFile.id);
208+
await this.assetRepository.deleteFiles([fullsizeFile]);
209209
}
210210
}
211211

0 commit comments

Comments
 (0)