update job queries

This commit is contained in:
mertalev
2026-04-03 01:55:41 -04:00
parent 1d713f4829
commit f633612427
4 changed files with 99 additions and 62 deletions
@@ -315,8 +315,10 @@ select
"asset_exif"."lockedProperties" "asset_exif"."lockedProperties"
from from
"asset_exif" "asset_exif"
inner join "asset" on "asset"."id" = "asset_exif"."assetId"
where where
"asset_exif"."assetId" = $1 "asset_exif"."assetId" = $1
and "asset"."status" != 'partial'
-- AssetJobRepository.getAlbumThumbnailFiles -- AssetJobRepository.getAlbumThumbnailFiles
select select
@@ -326,8 +328,10 @@ select
"asset_file"."isEdited" "asset_file"."isEdited"
from from
"asset_file" "asset_file"
inner join "asset" on "asset"."id" = "asset_file"."assetId"
where where
"asset_file"."assetId" = $1 "asset_file"."assetId" = $1
and "asset"."status" != 'partial'
and "asset_file"."type" = $2 and "asset_file"."type" = $2
-- AssetJobRepository.streamForSearchDuplicates -- AssetJobRepository.streamForSearchDuplicates
@@ -454,6 +458,7 @@ from
"asset" "asset"
where where
"asset"."id" = $2 "asset"."id" = $2
and "asset"."status" != 'partial'
-- AssetJobRepository.getForSyncAssets -- AssetJobRepository.getForSyncAssets
select select
@@ -467,6 +472,7 @@ from
"asset" "asset"
where where
"asset"."id" = any ($1::uuid[]) "asset"."id" = any ($1::uuid[])
and "asset"."status" != 'partial'
-- AssetJobRepository.getForAssetDeletion -- AssetJobRepository.getForAssetDeletion
select select
@@ -733,6 +739,7 @@ where
"asset_job_status"."ocrAt" is null "asset_job_status"."ocrAt" is null
and "asset"."deletedAt" is null and "asset"."deletedAt" is null
and "asset"."visibility" != $1 and "asset"."visibility" != $1
and "asset"."status" != 'partial'
-- AssetJobRepository.streamForMigrationJob -- AssetJobRepository.streamForMigrationJob
select select
+38 -19
View File
@@ -117,25 +117,44 @@ where
and "ownerId" = $2 and "ownerId" = $2
-- AssetRepository.setComplete -- AssetRepository.setComplete
update "asset" as "complete_asset" with
set "completed_asset" as (
"status" = 'active', update "asset" as "complete_asset"
"visibility" = case set
when ( "status" = 'active',
"complete_asset"."type" = 'VIDEO' "visibility" = case
and exists ( when (
select "complete_asset"."type" = 'VIDEO'
from and exists (
"asset" select
where from
"complete_asset"."id" = "asset"."livePhotoVideoId" "asset"
) where
) then 'hidden'::asset_visibility_enum "complete_asset"."id" = "asset"."livePhotoVideoId"
else 'timeline'::asset_visibility_enum )
end ) then 'hidden'::asset_visibility_enum
where else 'timeline'::asset_visibility_enum
"id" = $1 end
and "status" = 'partial' where
"id" = $1
and "status" = 'partial'
returning
*
),
"shared_link" as (
insert into
"album_asset" ("albumId", "assetId")
select
$2 as "albumId",
"completed_asset"."id"
from
"completed_asset"
on conflict do nothing
)
select
*
from
"completed_asset"
-- AssetRepository.removeAndDecrementQuota -- AssetRepository.removeAndDecrementQuota
with with
@@ -160,8 +160,10 @@ export class AssetJobRepository {
async getLockedPropertiesForMetadataExtraction(assetId: string) { async getLockedPropertiesForMetadataExtraction(assetId: string) {
return this.db return this.db
.selectFrom('asset_exif') .selectFrom('asset_exif')
.innerJoin('asset', 'asset.id', 'asset_exif.assetId')
.select('asset_exif.lockedProperties') .select('asset_exif.lockedProperties')
.where('asset_exif.assetId', '=', assetId) .where('asset_exif.assetId', '=', assetId)
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.executeTakeFirst() .executeTakeFirst()
.then((row) => row?.lockedProperties ?? []); .then((row) => row?.lockedProperties ?? []);
} }
@@ -170,8 +172,10 @@ export class AssetJobRepository {
getAlbumThumbnailFiles(id: string, fileType?: AssetFileType) { getAlbumThumbnailFiles(id: string, fileType?: AssetFileType) {
return this.db return this.db
.selectFrom('asset_file') .selectFrom('asset_file')
.innerJoin('asset', 'asset.id', 'asset_file.assetId')
.select(columns.assetFiles) .select(columns.assetFiles)
.where('asset_file.assetId', '=', id) .where('asset_file.assetId', '=', id)
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.$if(!!fileType, (qb) => qb.where('asset_file.type', '=', fileType!)) .$if(!!fileType, (qb) => qb.where('asset_file.type', '=', fileType!))
.execute(); .execute();
} }
@@ -250,6 +254,7 @@ export class AssetJobRepository {
.selectFrom('asset') .selectFrom('asset')
.select((eb) => ['asset.visibility', withFilePath(eb, AssetFileType.Preview).as('previewFile')]) .select((eb) => ['asset.visibility', withFilePath(eb, AssetFileType.Preview).as('previewFile')])
.where('asset.id', '=', id) .where('asset.id', '=', id)
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.executeTakeFirst(); .executeTakeFirst();
} }
@@ -266,6 +271,7 @@ export class AssetJobRepository {
'asset.fileModifiedAt', 'asset.fileModifiedAt',
]) ])
.where('asset.id', '=', anyUuid(ids)) .where('asset.id', '=', anyUuid(ids))
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.execute(); .execute();
} }
@@ -464,6 +470,7 @@ export class AssetJobRepository {
) )
.where('asset.deletedAt', 'is', null) .where('asset.deletedAt', 'is', null)
.where('asset.visibility', '!=', AssetVisibility.Hidden) .where('asset.visibility', '!=', AssetVisibility.Hidden)
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.stream(); .stream();
} }
+47 -43
View File
@@ -439,53 +439,57 @@ export class AssetRepository {
.executeTakeFirst(); .executeTakeFirst();
} }
@GenerateSql({ params: [DummyValue.UUID] }) @GenerateSql({ params: [DummyValue.UUID, { albumId: DummyValue.UUID, id: DummyValue.UUID }] })
setComplete(assetId: string, sharedLink?: { albumId?: string | null; id: string }) { setComplete(assetId: string, sharedLink?: { albumId?: string | null; id: string }) {
let query = this.db.with('completed_asset', (qb) => const completedAsset = this.db
qb .updateTable('asset as complete_asset')
.updateTable('asset as complete_asset') .set((eb) => ({
.set((eb) => ({ status: sql.lit(AssetStatus.Active),
status: sql.lit(AssetStatus.Active), visibility: eb
visibility: eb .case()
.case() .when(
.when( eb.and([
eb.and([ eb('complete_asset.type', '=', sql.lit(AssetType.Video)),
eb('complete_asset.type', '=', sql.lit(AssetType.Video)), eb.exists(eb.selectFrom('asset').whereRef('complete_asset.id', '=', 'asset.livePhotoVideoId')),
eb.exists(eb.selectFrom('asset').whereRef('complete_asset.id', '=', 'asset.livePhotoVideoId')), ]),
]),
)
.then(sql<AssetVisibility>`'hidden'::asset_visibility_enum`)
.else(sql<AssetVisibility>`'timeline'::asset_visibility_enum`)
.end(),
}))
.where('id', '=', assetId)
.where('status', '=', sql.lit(AssetStatus.Partial))
.returningAll(),
);
if (sharedLink?.albumId) {
(query as any) = query.with('shared_link', (qb) =>
qb
.insertInto('album_asset')
.columns(['albumId', 'assetId'])
.expression((eb) =>
eb.selectFrom('completed_asset').select([eb.val(sharedLink.albumId).as('albumId'), 'completed_asset.id']),
) )
.onConflict((oc) => oc.doNothing()), .then(sql<AssetVisibility>`'hidden'::asset_visibility_enum`)
); .else(sql<AssetVisibility>`'timeline'::asset_visibility_enum`)
} else if (sharedLink) { .end(),
(query as any) = query.with('shared_link', (qb) => }))
qb .where('id', '=', assetId)
.insertInto('shared_link_asset') .where('status', '=', sql.lit(AssetStatus.Partial))
.columns(['sharedLinkId', 'assetId']) .returningAll();
.expression((eb) => if (!sharedLink) {
eb.selectFrom('completed_asset').select([eb.val(sharedLink.id).as('sharedLinkId'), 'completed_asset.id']), return completedAsset.executeTakeFirst();
)
.onConflict((oc) => oc.doNothing()),
);
} }
return query.selectFrom('completed_asset').selectAll().executeTakeFirst(); return this.db
.with('completed_asset', () => completedAsset)
.with('shared_link', (qb) =>
sharedLink?.albumId
? qb
.insertInto('album_asset')
.columns(['albumId', 'assetId'])
.expression((eb) =>
eb
.selectFrom('completed_asset')
.select([eb.val(sharedLink.albumId).as('albumId'), 'completed_asset.id']),
)
.onConflict((oc) => oc.doNothing())
: qb
.insertInto('shared_link_asset')
.columns(['sharedLinkId', 'assetId'])
.expression((eb) =>
eb
.selectFrom('completed_asset')
.select([eb.val(sharedLink.id).as('sharedLinkId'), 'completed_asset.id']),
)
.onConflict((oc) => oc.doNothing()),
)
.selectFrom('completed_asset')
.selectAll()
.executeTakeFirst();
} }
@GenerateSql({ params: [DummyValue.UUID] }) @GenerateSql({ params: [DummyValue.UUID] })