Skip to content

Commit

Permalink
Remove only maia annotations of deleted images
Browse files Browse the repository at this point in the history
  • Loading branch information
lehecht committed Jun 7, 2024
1 parent 5669f68 commit fb7ed27
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/Jobs/DetectionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Queue;
use Biigle\Image;
use Biigle\ImageAnnotation;
use Illuminate\Support\Arr;

abstract class DetectionJob implements ShouldQueue
{
Expand Down Expand Up @@ -219,13 +219,25 @@ protected function createMaiaAnnotations(array $annotations)
return $this->createMaiaAnnotation($annotation);
}, $annotations);

// Remove annotations of already deleted images.
foreach ($maiaAnnotations as $idx => $a) {
if (Image::where('id', '=', $a['image_id'])->doesntExist()) {
ImageAnnotation::where('image_id', '=', $a['image_id'])->delete();
unset($maiaAnnotations[$idx]);
// Remove maia annotations of deleted images
$deletedImgId = [];
$maiaAnnotations = Arr::where($maiaAnnotations, function ($a) use ($deletedImgId) {
$imgId = $a['image_id'];
if(Arr::has($deletedImgId, $imgId)) {
if($deletedImgId[$imgId]) {
return false;
}
} else {
$isDeleted = Image::where('id', '=', $imgId)->doesntExist();
if($isDeleted) {
$deletedImgId[$imgId] = true;
return false;
} else {
$deletedImgId[$imgId] = false;
}
}
}
return true;
});

// Chunk the insert because PDO's maximum number of query parameters is
// 65535. Each annotation has 7 parameters so we can store roughly 9000
Expand Down

0 comments on commit fb7ed27

Please sign in to comment.