Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit aad892a

Browse files
authored
Merge pull request #41 from biigle/sim-sort
Largo sort
2 parents 73669e7 + e7841a6 commit aad892a

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

src/Jobs/PostprocessVolumeImport.php

+22-18
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Biigle\Modules\Sync\Jobs;
44

5-
use Biigle\ImageAnnotation;
5+
use Biigle\Image;
66
use Biigle\Jobs\Job;
77
use Biigle\Jobs\ProcessNewVolumeFiles;
8-
use Biigle\Modules\Largo\Jobs\GenerateImageAnnotationPatch;
9-
use Biigle\Modules\Largo\Jobs\GenerateVideoAnnotationPatch;
10-
use Biigle\VideoAnnotation;
8+
use Biigle\Modules\Largo\Jobs\ProcessAnnotatedImage;
9+
use Biigle\Modules\Largo\Jobs\ProcessAnnotatedVideo;
10+
use Biigle\Video;
1111
use Biigle\Volume;
1212
use Illuminate\Contracts\Queue\ShouldQueue;
1313
use Illuminate\Queue\InteractsWithQueue;
@@ -47,24 +47,28 @@ public function handle()
4747
ProcessNewVolumeFiles::dispatch($volume);
4848
});
4949

50-
if (class_exists(GenerateImageAnnotationPatch::class)) {
51-
ImageAnnotation::join('images', 'images.id', '=', 'image_annotations.image_id')
52-
->whereIn('images.volume_id', $this->ids)
53-
->select('image_annotations.id')
54-
->eachById(function ($annotation) {
55-
GenerateImageAnnotationPatch::dispatch($annotation)
50+
// Give the ProcessNewVolumeFiles jobs a head start so the file thumbnails are
51+
// generated (mostly) before the annotation thumbnails.
52+
$delay = now()->addSeconds(30);
53+
54+
if (class_exists(ProcessAnnotatedImage::class)) {
55+
Image::whereIn('images.volume_id', $this->ids)
56+
->whereHas('annotations')
57+
->eachById(function ($image) use ($delay) {
58+
ProcessAnnotatedImage::dispatch($image)
59+
->delay($delay)
5660
->onQueue(config('largo.generate_annotation_patch_queue'));
57-
}, 1000, 'image_annotations.id', 'id');
61+
}, 1000);
5862
}
5963

60-
if (class_exists(GenerateVideoAnnotationPatch::class)) {
61-
VideoAnnotation::join('videos', 'videos.id', '=', 'video_annotations.video_id')
62-
->whereIn('videos.volume_id', $this->ids)
63-
->select('video_annotations.id')
64-
->eachById(function ($annotation) {
65-
GenerateVideoAnnotationPatch::dispatch($annotation)
64+
if (class_exists(ProcessAnnotatedVideo::class)) {
65+
Video::whereIn('videos.volume_id', $this->ids)
66+
->whereHas('annotations')
67+
->eachById(function ($video) use ($delay) {
68+
ProcessAnnotatedVideo::dispatch($video)
69+
->delay($delay)
6670
->onQueue(config('largo.generate_annotation_patch_queue'));
67-
}, 1000, 'video_annotations.id', 'id');
71+
}, 1000);
6872
}
6973
}
7074
}

tests/Jobs/PostprocessVolumeImportTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace Biigle\Tests\Modules\Sync\Jobs;
44

55
use Biigle\Jobs\ProcessNewVolumeFiles;
6-
use Biigle\Modules\Largo\Jobs\GenerateImageAnnotationPatch;
7-
use Biigle\Modules\Largo\Jobs\GenerateVideoAnnotationPatch;
6+
use Biigle\Modules\Largo\Jobs\ProcessAnnotatedImage;
7+
use Biigle\Modules\Largo\Jobs\ProcessAnnotatedVideo;
88
use Biigle\Modules\Sync\Jobs\PostprocessVolumeImport;
99
use Biigle\Tests\ImageAnnotationTest;
1010
use Biigle\Tests\ImageTest;
@@ -20,34 +20,34 @@ public function testHandleVolumeImages()
2020
$job = new PostprocessVolumeImport(collect([$image->volume]));
2121
$job->handle();
2222
Queue::assertPushed(ProcessNewVolumeFiles::class);
23-
Queue::assertNotPushed(GenerateImageAnnotationPatch::class);
23+
Queue::assertNotPushed(ProcessAnnotatedImage::class);
2424
}
2525

2626
public function testHandleImageAnnotationPatches()
2727
{
28-
if (!class_exists(GenerateImageAnnotationPatch::class)) {
29-
$this->markTestSkipped('Requires '.GenerateImageAnnotationPatch::class);
28+
if (!class_exists(ProcessAnnotatedImage::class)) {
29+
$this->markTestSkipped('Requires '.ProcessAnnotatedImage::class);
3030
}
3131

3232
$annotation = ImageAnnotationTest::create();
3333
$job = new PostprocessVolumeImport(collect([$annotation->image->volume]));
3434
$job->handle();
3535
// One job for the creation of the annotation and one job by
3636
// PostprocessVolumeImport.
37-
$this->assertCount(2, Queue::pushed(GenerateImageAnnotationPatch::class));
37+
$this->assertCount(2, Queue::pushed(ProcessAnnotatedImage::class));
3838
}
3939

4040
public function testHandleVideoAnnotationPatches()
4141
{
42-
if (!class_exists(GenerateVideoAnnotationPatch::class)) {
43-
$this->markTestSkipped('Requires '.GenerateVideoAnnotationPatch::class);
42+
if (!class_exists(ProcessAnnotatedVideo::class)) {
43+
$this->markTestSkipped('Requires '.ProcessAnnotatedVideo::class);
4444
}
4545

4646
$annotation = VideoAnnotationTest::create();
4747
$job = new PostprocessVolumeImport(collect([$annotation->video->volume]));
4848
$job->handle();
4949
// One job for the creation of the annotation and one job by
5050
// PostprocessVolumeImport.
51-
$this->assertCount(2, Queue::pushed(GenerateVideoAnnotationPatch::class));
51+
$this->assertCount(2, Queue::pushed(ProcessAnnotatedVideo::class));
5252
}
5353
}

0 commit comments

Comments
 (0)