-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement pruning of training proposal feature vectors
Resolves #131
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Biigle\Modules\Maia\Listeners; | ||
|
||
use Biigle\Modules\Maia\Events\MaiaJobContinued; | ||
use Biigle\Modules\Maia\TrainingProposalFeatureVector; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
class PruneTrainingProposalFeatureVectors implements ShouldQueue | ||
{ | ||
/** | ||
* Handle the event. | ||
* | ||
* @param MaiaJobContinued $event | ||
* @return void | ||
*/ | ||
public function handle(MaiaJobContinued $event) | ||
{ | ||
$event->job | ||
->trainingProposals() | ||
->unselected() | ||
->select('id') | ||
->chunkById(1000, function ($chunk) { | ||
TrainingProposalFeatureVector::whereIn('id', $chunk->pluck('id')) | ||
->delete(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/Listeners/PruneTrainingProposalFeatureVectorsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Biigle\Tests\Modules\Maia\Listeners; | ||
|
||
use Biigle\Modules\Maia\Events\MaiaJobContinued; | ||
use Biigle\Modules\Maia\Listeners\PruneTrainingProposalFeatureVectors; | ||
use Biigle\Tests\Modules\Maia\TrainingProposalTest; | ||
use Biigle\Modules\Maia\TrainingProposalFeatureVector; | ||
use TestCase; | ||
|
||
class PruneTrainingProposalFeatureVectorsTest extends TestCase | ||
{ | ||
public function testHandle() | ||
{ | ||
$a = TrainingProposalTest::create(['selected' => true]); | ||
$af = TrainingProposalFeatureVector::factory()->create([ | ||
'id' => $a->id, | ||
'job_id' => $a->job_id, | ||
]); | ||
|
||
$a2 = TrainingProposalTest::create([ | ||
'job_id' => $a->job_id, | ||
'selected' => false, | ||
]); | ||
$af2 = TrainingProposalFeatureVector::factory()->create([ | ||
'id' => $a2->id, | ||
'job_id' => $a2->job_id, | ||
]); | ||
|
||
|
||
$listener = new PruneTrainingProposalFeatureVectors; | ||
$listener->handle(new MaiaJobContinued($a->job)); | ||
$this->assertNotNull($af->fresh()); | ||
$this->assertNull($af2->fresh()); | ||
} | ||
} |