Skip to content

Commit

Permalink
Merge pull request #136 from biigle/patch-1
Browse files Browse the repository at this point in the history
Fix generate mising command
  • Loading branch information
mzur authored Jan 31, 2024
2 parents 6100410 + 122b892 commit f48fae5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Console/Commands/GenerateMissing.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ protected function handleImageAnnotations(): void
$annotations = ImageAnnotation::join('images', 'images.id', '=', 'image_annotations.image_id')
// Order by image ID first because we want to submit the annotations in
// batches for each image.
// Order by annotation ID is appended automatically by lazyById below.
->orderBy('image_annotations.image_id')
->orderBy('image_annotations.id')
->select('image_annotations.id', 'image_annotations.image_id')
->when($this->option('volume'), function ($query) {
$query->where('images.volume_id', $this->option('volume'));
Expand All @@ -120,7 +120,7 @@ protected function handleImageAnnotations(): void
});

$this->line("Image annotations");
$this->handleAnnotations($annotations, 'image_annotations.id');
$this->handleAnnotations($annotations);
}

/**
Expand All @@ -131,8 +131,8 @@ protected function handleVideoAnnotations(): void
$annotations = VideoAnnotation::join('videos', 'videos.id', '=', 'video_annotations.video_id')
// Order by video ID first because we want to submit the annotations in
// batches for each video.
// Order by annotation ID is appended automatically by lazyById below.
->orderBy('video_annotations.video_id')
->orderBy('video_annotations.id')
->select('video_annotations.id', 'video_annotations.video_id')
->when($this->option('volume'), function ($query) {
$query->where('videos.volume_id', $this->option('volume'));
Expand All @@ -151,10 +151,10 @@ protected function handleVideoAnnotations(): void
});

$this->line("Video annotations");
$this->handleAnnotations($annotations, 'video_annotations.id');
$this->handleAnnotations($annotations);
}

protected function handleAnnotations(Builder $annotations, string $idColumn): void
protected function handleAnnotations(Builder $annotations): void
{
$pushToQueue = !$this->option('dry-run');
$storage = Storage::disk(config('largo.patch_storage_disk'));
Expand All @@ -170,8 +170,10 @@ protected function handleAnnotations(Builder $annotations, string $idColumn): vo

$chunkSize = (int) $this->option('chunk-size', 10000);

// lazyById() is crucial as we can't load all annotations at once!
$generator = $annotations->with('file')->lazyById($chunkSize, $idColumn, 'id');
// lazy() is crucial as we can't load all annotations at once!
// We can't use lazyById because we order by file ID first (to better batch
// annotations of the same file).
$generator = $annotations->with('file')->lazy($chunkSize);
foreach ($generator as $annotation) {
$progress->advance();

Expand Down

0 comments on commit f48fae5

Please sign in to comment.