mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
update job queries
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -117,6 +117,8 @@ where
|
|||||||
and "ownerId" = $2
|
and "ownerId" = $2
|
||||||
|
|
||||||
-- AssetRepository.setComplete
|
-- AssetRepository.setComplete
|
||||||
|
with
|
||||||
|
"completed_asset" as (
|
||||||
update "asset" as "complete_asset"
|
update "asset" as "complete_asset"
|
||||||
set
|
set
|
||||||
"status" = 'active',
|
"status" = 'active',
|
||||||
@@ -136,6 +138,23 @@ set
|
|||||||
where
|
where
|
||||||
"id" = $1
|
"id" = $1
|
||||||
and "status" = 'partial'
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -439,10 +439,9 @@ 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),
|
||||||
@@ -460,32 +459,37 @@ export class AssetRepository {
|
|||||||
}))
|
}))
|
||||||
.where('id', '=', assetId)
|
.where('id', '=', assetId)
|
||||||
.where('status', '=', sql.lit(AssetStatus.Partial))
|
.where('status', '=', sql.lit(AssetStatus.Partial))
|
||||||
.returningAll(),
|
.returningAll();
|
||||||
);
|
if (!sharedLink) {
|
||||||
|
return completedAsset.executeTakeFirst();
|
||||||
|
}
|
||||||
|
|
||||||
if (sharedLink?.albumId) {
|
return this.db
|
||||||
(query as any) = query.with('shared_link', (qb) =>
|
.with('completed_asset', () => completedAsset)
|
||||||
qb
|
.with('shared_link', (qb) =>
|
||||||
|
sharedLink?.albumId
|
||||||
|
? qb
|
||||||
.insertInto('album_asset')
|
.insertInto('album_asset')
|
||||||
.columns(['albumId', 'assetId'])
|
.columns(['albumId', 'assetId'])
|
||||||
.expression((eb) =>
|
.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()),
|
.onConflict((oc) => oc.doNothing())
|
||||||
);
|
: qb
|
||||||
} else if (sharedLink) {
|
|
||||||
(query as any) = query.with('shared_link', (qb) =>
|
|
||||||
qb
|
|
||||||
.insertInto('shared_link_asset')
|
.insertInto('shared_link_asset')
|
||||||
.columns(['sharedLinkId', 'assetId'])
|
.columns(['sharedLinkId', 'assetId'])
|
||||||
.expression((eb) =>
|
.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()),
|
.onConflict((oc) => oc.doNothing()),
|
||||||
);
|
)
|
||||||
}
|
.selectFrom('completed_asset')
|
||||||
|
.selectAll()
|
||||||
return query.selectFrom('completed_asset').selectAll().executeTakeFirst();
|
.executeTakeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID] })
|
@GenerateSql({ params: [DummyValue.UUID] })
|
||||||
|
|||||||
Reference in New Issue
Block a user