From f4edb6c4bd095a480875a5931773f95201c58080 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Fri, 12 Jan 2024 19:39:45 -0500 Subject: [PATCH] feat(server): track metadata extracted at (#6352) --- .../src/domain/metadata/metadata.service.ts | 5 +++++ .../infra/entities/asset-job-status.entity.ts | 3 +++ .../1705094221536-AddMetadataExtractedAt.ts | 19 +++++++++++++++++++ .../infra/repositories/asset.repository.ts | 5 +++-- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 server/src/infra/migrations/1705094221536-AddMetadataExtractedAt.ts diff --git a/server/src/domain/metadata/metadata.service.ts b/server/src/domain/metadata/metadata.service.ts index a00c504768..fa892d42f5 100644 --- a/server/src/domain/metadata/metadata.service.ts +++ b/server/src/domain/metadata/metadata.service.ts @@ -252,6 +252,11 @@ export class MetadataService { fileCreatedAt: exifData.dateTimeOriginal ?? undefined, }); + await this.assetRepository.upsertJobStatus({ + assetId: asset.id, + metadataExtractedAt: new Date(), + }); + return true; } diff --git a/server/src/infra/entities/asset-job-status.entity.ts b/server/src/infra/entities/asset-job-status.entity.ts index 36905cc8f3..f1965fbdb8 100644 --- a/server/src/infra/entities/asset-job-status.entity.ts +++ b/server/src/infra/entities/asset-job-status.entity.ts @@ -12,4 +12,7 @@ export class AssetJobStatusEntity { @Column({ type: 'timestamptz', nullable: true }) facesRecognizedAt!: Date | null; + + @Column({ type: 'timestamptz', nullable: true }) + metadataExtractedAt!: Date | null; } diff --git a/server/src/infra/migrations/1705094221536-AddMetadataExtractedAt.ts b/server/src/infra/migrations/1705094221536-AddMetadataExtractedAt.ts new file mode 100644 index 0000000000..e76d095c10 --- /dev/null +++ b/server/src/infra/migrations/1705094221536-AddMetadataExtractedAt.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class AddMetadataExtractedAt1705094221536 implements MigrationInterface { + name = 'AddMetadataExtractedAt1705094221536'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "asset_job_status" ADD "metadataExtractedAt" TIMESTAMP WITH TIME ZONE`); + await queryRunner.query(` + UPDATE "asset_job_status" + SET "metadataExtractedAt" = NOW() + FROM "exif" + WHERE "exif"."assetId" = "asset_job_status"."assetId"; +`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "asset_job_status" DROP COLUMN "metadataExtractedAt"`); + } +} diff --git a/server/src/infra/repositories/asset.repository.ts b/server/src/infra/repositories/asset.repository.ts index f250dbeda8..f734cb8ba3 100644 --- a/server/src/infra/repositories/asset.repository.ts +++ b/server/src/infra/repositories/asset.repository.ts @@ -474,11 +474,12 @@ export class AssetRepository implements IAssetRepository { case WithoutProperty.EXIF: relations = { exifInfo: true, + jobStatus: true, }; where = { isVisible: true, - exifInfo: { - assetId: IsNull(), + jobStatus: { + metadataExtractedAt: IsNull(), }, }; break;