fix(server): index edited assets in smart search (#32300)
(cherry picked from commit adca900fe277bd6dff93b96b6a7841a8632ce62b)
This commit is contained in:
@@ -211,6 +211,36 @@ describe(SmartInfoService.name, () => {
|
||||
expect(mocks.search.upsert).toHaveBeenCalledWith(asset.id, '[0.01, 0.02, 0.03]');
|
||||
});
|
||||
|
||||
it('should use the edited preview when both preview variants exist', async () => {
|
||||
const asset = AssetFactory.from()
|
||||
.file({ type: AssetFileType.Preview, isEdited: false, path: 'original-preview' })
|
||||
.file({ type: AssetFileType.Preview, isEdited: true, path: 'edited-preview' })
|
||||
.build();
|
||||
mocks.machineLearning.encodeImage.mockResolvedValue('[0.01, 0.02, 0.03]');
|
||||
mocks.assetJob.getForClipEncoding.mockResolvedValue(asset);
|
||||
|
||||
expect(await sut.handleEncodeClip({ id: asset.id })).toEqual(JobStatus.Success);
|
||||
expect(mocks.machineLearning.encodeImage).toHaveBeenCalledWith(
|
||||
'edited-preview',
|
||||
expect.objectContaining({ modelName: 'ViT-B-32__openai' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should select the edited preview regardless of file order', async () => {
|
||||
const asset = AssetFactory.from()
|
||||
.file({ type: AssetFileType.Preview, isEdited: true, path: 'edited-preview' })
|
||||
.file({ type: AssetFileType.Preview, isEdited: false, path: 'original-preview' })
|
||||
.build();
|
||||
mocks.machineLearning.encodeImage.mockResolvedValue('[0.01, 0.02, 0.03]');
|
||||
mocks.assetJob.getForClipEncoding.mockResolvedValue(asset);
|
||||
|
||||
expect(await sut.handleEncodeClip({ id: asset.id })).toEqual(JobStatus.Success);
|
||||
expect(mocks.machineLearning.encodeImage).toHaveBeenCalledWith(
|
||||
'edited-preview',
|
||||
expect.objectContaining({ modelName: 'ViT-B-32__openai' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('should skip invisible assets', async () => {
|
||||
const asset = AssetFactory.from({ visibility: AssetVisibility.Hidden })
|
||||
.file({ type: AssetFileType.Preview })
|
||||
|
||||
@@ -92,7 +92,8 @@ export class SmartInfoService extends BaseService {
|
||||
}
|
||||
|
||||
const asset = await this.assetJobRepository.getForClipEncoding(id);
|
||||
if (!asset || asset.files.length !== 1) {
|
||||
const previewFile = asset?.files.find((file) => file.isEdited) ?? asset?.files[0];
|
||||
if (!asset || !previewFile) {
|
||||
return JobStatus.Failed;
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ export class SmartInfoService extends BaseService {
|
||||
return JobStatus.Skipped;
|
||||
}
|
||||
|
||||
const embedding = await this.machineLearningRepository.encodeImage(asset.files[0].path, machineLearning.clip);
|
||||
const embedding = await this.machineLearningRepository.encodeImage(previewFile.path, machineLearning.clip);
|
||||
|
||||
if (this.databaseRepository.isBusy(DatabaseLock.CLIPDimSize)) {
|
||||
this.logger.verbose(`Waiting for CLIP dimension size to be updated`);
|
||||
|
||||
Reference in New Issue
Block a user