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"
from
"asset_exif"
inner join "asset" on "asset"."id" = "asset_exif"."assetId"
where
"asset_exif"."assetId" = $1
and "asset"."status" != 'partial'
-- AssetJobRepository.getAlbumThumbnailFiles
select
@@ -326,8 +328,10 @@ select
"asset_file"."isEdited"
from
"asset_file"
inner join "asset" on "asset"."id" = "asset_file"."assetId"
where
"asset_file"."assetId" = $1
and "asset"."status" != 'partial'
and "asset_file"."type" = $2
-- AssetJobRepository.streamForSearchDuplicates
@@ -454,6 +458,7 @@ from
"asset"
where
"asset"."id" = $2
and "asset"."status" != 'partial'
-- AssetJobRepository.getForSyncAssets
select
@@ -467,6 +472,7 @@ from
"asset"
where
"asset"."id" = any ($1::uuid[])
and "asset"."status" != 'partial'
-- AssetJobRepository.getForAssetDeletion
select
@@ -733,6 +739,7 @@ where
"asset_job_status"."ocrAt" is null
and "asset"."deletedAt" is null
and "asset"."visibility" != $1
and "asset"."status" != 'partial'
-- AssetJobRepository.streamForMigrationJob
select
+19
View File
@@ -117,6 +117,8 @@ where
and "ownerId" = $2
-- AssetRepository.setComplete
with
"completed_asset" as (
update "asset" as "complete_asset"
set
"status" = 'active',
@@ -136,6 +138,23 @@ set
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
with
@@ -160,8 +160,10 @@ export class AssetJobRepository {
async getLockedPropertiesForMetadataExtraction(assetId: string) {
return this.db
.selectFrom('asset_exif')
.innerJoin('asset', 'asset.id', 'asset_exif.assetId')
.select('asset_exif.lockedProperties')
.where('asset_exif.assetId', '=', assetId)
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.executeTakeFirst()
.then((row) => row?.lockedProperties ?? []);
}
@@ -170,8 +172,10 @@ export class AssetJobRepository {
getAlbumThumbnailFiles(id: string, fileType?: AssetFileType) {
return this.db
.selectFrom('asset_file')
.innerJoin('asset', 'asset.id', 'asset_file.assetId')
.select(columns.assetFiles)
.where('asset_file.assetId', '=', id)
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.$if(!!fileType, (qb) => qb.where('asset_file.type', '=', fileType!))
.execute();
}
@@ -250,6 +254,7 @@ export class AssetJobRepository {
.selectFrom('asset')
.select((eb) => ['asset.visibility', withFilePath(eb, AssetFileType.Preview).as('previewFile')])
.where('asset.id', '=', id)
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.executeTakeFirst();
}
@@ -266,6 +271,7 @@ export class AssetJobRepository {
'asset.fileModifiedAt',
])
.where('asset.id', '=', anyUuid(ids))
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.execute();
}
@@ -464,6 +470,7 @@ export class AssetJobRepository {
)
.where('asset.deletedAt', 'is', null)
.where('asset.visibility', '!=', AssetVisibility.Hidden)
.where('asset.status', '!=', sql.lit(AssetStatus.Partial))
.stream();
}
+23 -19
View File
@@ -439,10 +439,9 @@ export class AssetRepository {
.executeTakeFirst();
}
@GenerateSql({ params: [DummyValue.UUID] })
@GenerateSql({ params: [DummyValue.UUID, { albumId: DummyValue.UUID, id: DummyValue.UUID }] })
setComplete(assetId: string, sharedLink?: { albumId?: string | null; id: string }) {
let query = this.db.with('completed_asset', (qb) =>
qb
const completedAsset = this.db
.updateTable('asset as complete_asset')
.set((eb) => ({
status: sql.lit(AssetStatus.Active),
@@ -460,32 +459,37 @@ export class AssetRepository {
}))
.where('id', '=', assetId)
.where('status', '=', sql.lit(AssetStatus.Partial))
.returningAll(),
);
.returningAll();
if (!sharedLink) {
return completedAsset.executeTakeFirst();
}
if (sharedLink?.albumId) {
(query as any) = query.with('shared_link', (qb) =>
qb
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']),
eb
.selectFrom('completed_asset')
.select([eb.val(sharedLink.albumId).as('albumId'), 'completed_asset.id']),
)
.onConflict((oc) => oc.doNothing()),
);
} else if (sharedLink) {
(query as any) = query.with('shared_link', (qb) =>
qb
.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']),
eb
.selectFrom('completed_asset')
.select([eb.val(sharedLink.id).as('sharedLinkId'), 'completed_asset.id']),
)
.onConflict((oc) => oc.doNothing()),
);
}
return query.selectFrom('completed_asset').selectAll().executeTakeFirst();
)
.selectFrom('completed_asset')
.selectAll()
.executeTakeFirst();
}
@GenerateSql({ params: [DummyValue.UUID] })