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

refactor(server): track thumbnail jobs in job status table (#11908)

refactor: track thumbnail jobs in job status table
This commit is contained in:
Jason Rasmussen 2024-08-19 13:50:00 -04:00 committed by GitHub
parent 8338657eaa
commit d9698884bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 9 deletions

View File

@ -18,4 +18,10 @@ export class AssetJobStatusEntity {
@Column({ type: 'timestamptz', nullable: true })
duplicatesDetectedAt!: Date | null;
@Column({ type: 'timestamptz', nullable: true })
previewAt!: Date | null;
@Column({ type: 'timestamptz', nullable: true })
thumbnailAt!: Date | null;
}

View File

@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddThumbnailJobStatus1724080823160 implements MigrationInterface {
name = 'AddThumbnailJobStatus1724080823160';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "asset_job_status" ADD "previewAt" TIMESTAMP WITH TIME ZONE`);
await queryRunner.query(`ALTER TABLE "asset_job_status" ADD "thumbnailAt" TIMESTAMP WITH TIME ZONE`);
await queryRunner.query(`UPDATE "asset_job_status" SET "previewAt" = NOW() FROM "assets" WHERE "assetId" = "assets"."id" AND "assets"."previewPath" IS NOT NULL`);
await queryRunner.query(`UPDATE "asset_job_status" SET "thumbnailAt" = NOW() FROM "assets" WHERE "assetId" = "assets"."id" AND "assets"."thumbnailPath" IS NOT NULL`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "asset_job_status" DROP COLUMN "thumbnailAt"`);
await queryRunner.query(`ALTER TABLE "asset_job_status" DROP COLUMN "previewAt"`);
}
}

View File

@ -391,11 +391,10 @@ export class AssetRepository implements IAssetRepository {
switch (property) {
case WithoutProperty.THUMBNAIL: {
relations = { jobStatus: true };
where = [
{ previewPath: IsNull(), isVisible: true },
{ previewPath: '', isVisible: true },
{ thumbnailPath: IsNull(), isVisible: true },
{ thumbnailPath: '', isVisible: true },
{ jobStatus: { previewAt: IsNull() }, isVisible: true },
{ jobStatus: { thumbnailAt: IsNull() }, isVisible: true },
{ thumbhash: IsNull(), isVisible: true },
];
break;
@ -429,7 +428,7 @@ export class AssetRepository implements IAssetRepository {
};
where = {
isVisible: true,
previewPath: Not(IsNull()),
jobStatus: { previewAt: Not(IsNull()) },
smartSearch: {
embedding: IsNull(),
},
@ -439,10 +438,10 @@ export class AssetRepository implements IAssetRepository {
case WithoutProperty.DUPLICATE: {
where = {
previewPath: Not(IsNull()),
isVisible: true,
smartSearch: true,
jobStatus: {
previewAt: Not(IsNull()),
duplicatesDetectedAt: IsNull(),
},
};
@ -454,7 +453,9 @@ export class AssetRepository implements IAssetRepository {
smartInfo: true,
};
where = {
previewPath: Not(IsNull()),
jobStatus: {
previewAt: Not(IsNull()),
},
isVisible: true,
smartInfo: {
tags: IsNull(),
@ -469,13 +470,13 @@ export class AssetRepository implements IAssetRepository {
jobStatus: true,
};
where = {
previewPath: Not(IsNull()),
isVisible: true,
faces: {
assetId: IsNull(),
personId: IsNull(),
},
jobStatus: {
previewAt: Not(IsNull()),
facesRecognizedAt: IsNull(),
},
};
@ -487,7 +488,9 @@ export class AssetRepository implements IAssetRepository {
faces: true,
};
where = {
previewPath: Not(IsNull()),
jobStatus: {
previewAt: Not(IsNull()),
},
isVisible: true,
faces: {
assetId: Not(IsNull()),

View File

@ -178,11 +178,18 @@ export class MediaService {
}
const previewPath = await this.generateThumbnail(asset, AssetPathType.PREVIEW, image.previewFormat);
if (!previewPath) {
return JobStatus.SKIPPED;
}
if (asset.previewPath && asset.previewPath !== previewPath) {
this.logger.debug(`Deleting old preview for asset ${asset.id}`);
await this.storageRepository.unlink(asset.previewPath);
}
await this.assetRepository.update({ id: asset.id, previewPath });
await this.assetRepository.upsertJobStatus({ assetId: asset.id, previewAt: new Date() });
return JobStatus.SUCCESS;
}
@ -257,11 +264,18 @@ export class MediaService {
}
const thumbnailPath = await this.generateThumbnail(asset, AssetPathType.THUMBNAIL, image.thumbnailFormat);
if (!thumbnailPath) {
return JobStatus.SKIPPED;
}
if (asset.thumbnailPath && asset.thumbnailPath !== thumbnailPath) {
this.logger.debug(`Deleting old thumbnail for asset ${asset.id}`);
await this.storageRepository.unlink(asset.thumbnailPath);
}
await this.assetRepository.update({ id: asset.id, thumbnailPath });
await this.assetRepository.upsertJobStatus({ assetId: asset.id, thumbnailAt: new Date() });
return JobStatus.SUCCESS;
}