refactor: dedicated query for asset migration job (#17631)

This commit is contained in:
Daniel Dietzler
2025-04-15 21:49:15 +02:00
committed by GitHub
parent 26f0ea4cb5
commit 21becbf1b0
6 changed files with 54 additions and 9 deletions

View File

@@ -191,13 +191,14 @@ describe(MediaService.name, () => {
describe('handleAssetMigration', () => {
it('should fail if asset does not exist', async () => {
mocks.assetJob.getForMigrationJob.mockResolvedValue(void 0);
await expect(sut.handleAssetMigration({ id: assetStub.image.id })).resolves.toBe(JobStatus.FAILED);
expect(mocks.move.getByEntity).not.toHaveBeenCalled();
});
it('should move asset files', async () => {
mocks.asset.getByIds.mockResolvedValue([assetStub.image]);
mocks.assetJob.getForMigrationJob.mockResolvedValue(assetStub.image);
mocks.move.create.mockResolvedValue({
entityId: assetStub.image.id,
id: 'move-id',

View File

@@ -121,7 +121,7 @@ export class MediaService extends BaseService {
@OnJob({ name: JobName.MIGRATE_ASSET, queue: QueueName.MIGRATION })
async handleAssetMigration({ id }: JobOf<JobName.MIGRATE_ASSET>): Promise<JobStatus> {
const { image } = await this.getConfig({ withCache: true });
const [asset] = await this.assetRepository.getByIds([id], { files: true });
const asset = await this.assetJobRepository.getForMigrationJob(id);
if (!asset) {
return JobStatus.FAILED;
}