Skip to content

High performance self-hosted photo and video management solution.

fix: memory generation (#25650)

Jason Rasmussen141be5cbc983
diff --git a/server/src/queries/asset.job.repository.sql b/server/src/queries/asset.job.repository.sql
index fae1123167..50f2c193fc 100644
--- a/server/src/queries/asset.job.repository.sql
+++ b/server/src/queries/asset.job.repository.sql
@@ -116,8 +116,22 @@ where
"asset"."deletedAt" is null
and "asset"."visibility" != $1
and (
- "asset_job_status"."previewAt" is null
- or "asset_job_status"."thumbnailAt" is null
+ not exists (
+ select
+ from
+ "asset_file"
+ where
+ "assetId" = "asset"."id"
+ and "asset_file"."type" = $2
+ )
+ or not exists (
+ select
+ from
+ "asset_file"
+ where
+ "assetId" = "asset"."id"
+ and "asset_file"."type" = $3
+ )
or "asset"."thumbhash" is null
)
@@ -292,7 +306,14 @@ from
where
"asset"."visibility" != $1
and "asset"."deletedAt" is null
- and "job_status"."previewAt" is not null
+ and exists (
+ select
+ from
+ "asset_file"
+ where
+ "assetId" = "asset"."id"
+ and "asset_file"."type" = $2
+ )
and not exists (
select
from
@@ -623,7 +644,14 @@ from
where
"asset"."visibility" != $1
and "asset"."deletedAt" is null
- and "job_status"."previewAt" is not null
+ and exists (
+ select
+ from
+ "asset_file"
+ where
+ "assetId" = "asset"."id"
+ and "asset_file"."type" = $2
+ )
order by
"asset"."fileCreatedAt" desc
diff --git a/server/src/queries/asset.repository.sql b/server/src/queries/asset.repository.sql
index 70d4602d26..0f3a458c35 100644
--- a/server/src/queries/asset.repository.sql
+++ b/server/src/queries/asset.repository.sql
@@ -134,8 +134,7 @@ with
"asset"
inner join "asset_job_status" on "asset"."id" = "asset_job_status"."assetId"
where
- "asset_job_status"."previewAt" is not null
- and (asset."localDateTime" at time zone 'UTC')::date = today.date
+ (asset."localDateTime" at time zone 'UTC')::date = today.date
and "asset"."ownerId" = any ($4::uuid[])
and "asset"."visibility" = $5
and exists (
diff --git a/server/src/repositories/asset-job.repository.ts b/server/src/repositories/asset-job.repository.ts
index 713f715c5c..1608f7b6f6 100644
--- a/server/src/repositories/asset-job.repository.ts
+++ b/server/src/repositories/asset-job.repository.ts
@@ -73,8 +73,22 @@ export class AssetJobRepository {
.innerJoin('asset_job_status', 'asset_job_status.assetId', 'asset.id')
.where((eb) =>
eb.or([
- eb('asset_job_status.previewAt', 'is', null),
- eb('asset_job_status.thumbnailAt', 'is', null),
+ eb.not((eb) =>
+ eb.exists((qb) =>
+ qb
+ .selectFrom('asset_file')
+ .whereRef('assetId', '=', 'asset.id')
+ .where('asset_file.type', '=', AssetFileType.Preview),
+ ),
+ ),
+ eb.not((eb) =>
+ eb.exists((qb) =>
+ qb
+ .selectFrom('asset_file')
+ .whereRef('assetId', '=', 'asset.id')
+ .where('asset_file.type', '=', AssetFileType.Thumbnail),
+ ),
+ ),
eb('asset.thumbhash', 'is', null),
]),
),
@@ -157,7 +171,14 @@ export class AssetJobRepository {
.where('asset.visibility', '!=', AssetVisibility.Hidden)
.where('asset.deletedAt', 'is', null)
.innerJoin('asset_job_status as job_status', 'assetId', 'asset.id')
- .where('job_status.previewAt', 'is not', null);
+ .where((eb) =>
+ eb.exists((qb) =>
+ qb
+ .selectFrom('asset_file')
+ .whereRef('assetId', '=', 'asset.id')
+ .where('asset_file.type', '=', AssetFileType.Preview),
+ ),
+ );
}
@GenerateSql({ params: [], stream: true })
diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts
index c1340754ea..1a060c4715 100644
--- a/server/src/repositories/asset.repository.ts
+++ b/server/src/repositories/asset.repository.ts
@@ -251,8 +251,6 @@ export class AssetRepository {
duplicatesDetectedAt: eb.ref('excluded.duplicatesDetectedAt'),
facesRecognizedAt: eb.ref('excluded.facesRecognizedAt'),
metadataExtractedAt: eb.ref('excluded.metadataExtractedAt'),
- previewAt: eb.ref('excluded.previewAt'),
- thumbnailAt: eb.ref('excluded.thumbnailAt'),
ocrAt: eb.ref('excluded.ocrAt'),
},
values[0],
@@ -361,7 +359,6 @@ export class AssetRepository {
.selectFrom('asset')
.selectAll('asset')
.innerJoin('asset_job_status', 'asset.id', 'asset_job_status.assetId')
- .where('asset_job_status.previewAt', 'is not', null)
.where(sql`(asset."localDateTime" at time zone 'UTC')::date`, '=', sql`today.date`)
.where('asset.ownerId', '=', anyUuid(ownerIds))
.where('asset.visibility', '=', AssetVisibility.Timeline)
diff --git a/server/src/schema/migrations/1769635093204-DropThumbnailJobStatusColumns.ts b/server/src/schema/migrations/1769635093204-DropThumbnailJobStatusColumns.ts
new file mode 100644
index 0000000000..9cd2f91b47
--- /dev/null
+++ b/server/src/schema/migrations/1769635093204-DropThumbnailJobStatusColumns.ts
@@ -0,0 +1,11 @@
+import { Kysely, sql } from 'kysely';
+
+export async function up(db: Kysely<any>): Promise<void> {
+ await sql`ALTER TABLE "asset_job_status" DROP COLUMN "previewAt";`.execute(db);
+ await sql`ALTER TABLE "asset_job_status" DROP COLUMN "thumbnailAt";`.execute(db);
+}
+
+export async function down(db: Kysely<any>): Promise<void> {
+ await sql`ALTER TABLE "asset_job_status" ADD "previewAt" timestamp with time zone;`.execute(db);
+ await sql`ALTER TABLE "asset_job_status" ADD "thumbnailAt" timestamp with time zone;`.execute(db);
+}
diff --git a/server/src/schema/tables/asset-job-status.table.ts b/server/src/schema/tables/asset-job-status.table.ts
index d68dbcb761..62194825e5 100644
--- a/server/src/schema/tables/asset-job-status.table.ts
+++ b/server/src/schema/tables/asset-job-status.table.ts
@@ -15,12 +15,6 @@ export class AssetJobStatusTable {
@Column({ type: 'timestamp with time zone', nullable: true })
duplicatesDetectedAt!: Timestamp | null;
- @Column({ type: 'timestamp with time zone', nullable: true })
- previewAt!: Timestamp | null;
-
- @Column({ type: 'timestamp with time zone', nullable: true })
- thumbnailAt!: Timestamp | null;
-
@Column({ type: 'timestamp with time zone', nullable: true })
ocrAt!: Timestamp | null;
}
diff --git a/server/test/medium.factory.ts b/server/test/medium.factory.ts
index ac3ffed794..153b568222 100644
--- a/server/test/medium.factory.ts
+++ b/server/test/medium.factory.ts
@@ -601,8 +601,6 @@ const assetJobStatusInsert = (
duplicatesDetectedAt: date,
facesRecognizedAt: date,
metadataExtractedAt: date,
- previewAt: date,
- thumbnailAt: date,
};
return {