Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chunk annotations and annotation labels #778

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions app/Jobs/CloneImagesOrVideos.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ private function copyImageAnnotation($volume, $copy, $selectedFileIds, $selected
}

$chunkSize = 100;
$parameterLimit = 10000;
$newImageIds = $copy->images()->orderBy('id')->pluck('id');
$volume->images()
->with([
Expand All @@ -267,7 +268,7 @@ private function copyImageAnnotation($volume, $copy, $selectedFileIds, $selected
$newImageIds,
$chunkSize,
$usedAnnotationIds,
$selectedLabelIds
$parameterLimit,
) {
$insertData = [];
$chunkNewImageIds = [];
Expand All @@ -285,7 +286,8 @@ private function copyImageAnnotation($volume, $copy, $selectedFileIds, $selected

}
}
ImageAnnotation::insert($insertData);
collect($insertData)->chunk($parameterLimit)->each(fn ($chunk) => ImageAnnotation::insert($chunk->toArray()));

// Get the IDs of all newly inserted annotations. Ordering is essential.
$newAnnotationIds = ImageAnnotation::whereIn('image_id', $chunkNewImageIds)
->orderBy('id')
Expand All @@ -302,7 +304,8 @@ private function copyImageAnnotation($volume, $copy, $selectedFileIds, $selected
}
}
}
ImageAnnotationLabel::insert($insertData);
collect($insertData)->chunk($parameterLimit)->each(fn ($chunk) => ImageAnnotationLabel::insert($chunk->toArray()));

});
}

Expand Down Expand Up @@ -410,6 +413,7 @@ private function copyVideoAnnotation($volume, $copy, $selectedFileIds, $selected
}

$chunkSize = 100;
$parameterLimit = 10000;
$newVideoIds = $copy->videos()->orderBy('id')->pluck('id');
$volume->videos()
->with([
Expand All @@ -424,7 +428,7 @@ private function copyVideoAnnotation($volume, $copy, $selectedFileIds, $selected
$newVideoIds,
$chunkSize,
$usedAnnotationIds,
$selectedLabelIds
$parameterLimit,
) {
$insertData = [];
$chunkNewVideoIds = [];
Expand All @@ -442,7 +446,9 @@ private function copyVideoAnnotation($volume, $copy, $selectedFileIds, $selected

}
}
VideoAnnotation::insert($insertData);
collect($insertData)->chunk($parameterLimit)->each(fn ($chunk) => VideoAnnotation::insert($chunk->toArray()));


// Get the IDs of all newly inserted annotations. Ordering is essential.
$newAnnotationIds = VideoAnnotation::whereIn('video_id', $chunkNewVideoIds)
->orderBy('id')
Expand All @@ -459,7 +465,8 @@ private function copyVideoAnnotation($volume, $copy, $selectedFileIds, $selected
}
}
}
VideoAnnotationLabel::insert($insertData);
collect($insertData)->chunk($parameterLimit)->each(fn ($chunk) => VideoAnnotationLabel::insert($chunk->toArray()));

});
}

Expand Down