feat(server): generate all thumbnails for an asset in one job (#13012)

* wip

cleanup

add success logs, rename method

do thumbhash too

fixes

fix tests

handle `notify`

wip refactor

refactor

* update tests

* update sql

* pr feedback

* remove unused code

* formatting
This commit is contained in:
Mert
2024-09-28 13:47:24 -04:00
committed by GitHub
parent 995f0fda47
commit 2bcd27e166
22 changed files with 574 additions and 542 deletions
+21 -28
View File
@@ -281,7 +281,7 @@ export class JobService {
case JobName.STORAGE_TEMPLATE_MIGRATION_SINGLE: {
if (item.data.source === 'upload' || item.data.source === 'copy') {
await this.jobRepository.queue({ name: JobName.GENERATE_PREVIEW, data: item.data });
await this.jobRepository.queue({ name: JobName.GENERATE_THUMBNAILS, data: item.data });
}
break;
}
@@ -295,40 +295,33 @@ export class JobService {
break;
}
case JobName.GENERATE_PREVIEW: {
const jobs: JobItem[] = [
{ name: JobName.GENERATE_THUMBNAIL, data: item.data },
{ name: JobName.GENERATE_THUMBHASH, data: item.data },
];
if (item.data.source === 'upload') {
jobs.push({ name: JobName.SMART_SEARCH, data: item.data }, { name: JobName.FACE_DETECTION, data: item.data });
const [asset] = await this.assetRepository.getByIds([item.data.id]);
if (asset) {
if (asset.type === AssetType.VIDEO) {
jobs.push({ name: JobName.VIDEO_CONVERSION, data: item.data });
} else if (asset.livePhotoVideoId) {
jobs.push({ name: JobName.VIDEO_CONVERSION, data: { id: asset.livePhotoVideoId } });
}
}
}
await this.jobRepository.queueAll(jobs);
break;
}
case JobName.GENERATE_THUMBNAIL: {
if (!(item.data.notify || item.data.source === 'upload')) {
case JobName.GENERATE_THUMBNAILS: {
if (!item.data.notify && item.data.source !== 'upload') {
break;
}
const [asset] = await this.assetRepository.getByIdsWithAllRelations([item.data.id]);
if (!asset) {
this.logger.warn(`Could not find asset ${item.data.id} after generating thumbnails`);
break;
}
// Only live-photo motion part will be marked as not visible immediately on upload. Skip notifying clients
if (asset && asset.isVisible) {
const jobs: JobItem[] = [
{ name: JobName.SMART_SEARCH, data: item.data },
{ name: JobName.FACE_DETECTION, data: item.data },
];
if (asset.type === AssetType.VIDEO) {
jobs.push({ name: JobName.VIDEO_CONVERSION, data: item.data });
} else if (asset.livePhotoVideoId) {
jobs.push({ name: JobName.VIDEO_CONVERSION, data: { id: asset.livePhotoVideoId } });
}
await this.jobRepository.queueAll(jobs);
if (asset.isVisible) {
this.eventRepository.clientSend(ClientEvent.UPLOAD_SUCCESS, asset.ownerId, mapAsset(asset));
}
break;
}