Skip to content

Commit c38e197

Browse files
authored
Merge pull request #137 from cwilby/master
Use `eachById` in `mailbox:clean`
2 parents 0f88e88 + e69ad08 commit c38e197

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/Console/CleanEmails.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ public function handle()
3737

3838
$modelClass::where('created_at', '<', $cutOffDate)
3939
->select('id')
40-
->chunk(100, function ($models) use ($modelClass) {
41-
foreach ($models as $model) {
42-
$modelInstance = $modelClass::find($model->id);
43-
$modelInstance->delete();
44-
$this->amountDeleted++;
45-
}
40+
->eachById(count: 100, callback: function ($model) {
41+
$model->delete();
42+
$this->amountDeleted++;
4643
});
4744

4845
$this->info("Deleted {$this->amountDeleted} record(s) from the Mailbox logs.");

src/Routing/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Router
2424
/** @var Container */
2525
protected $container;
2626

27-
public function __construct(?Container $container = null)
27+
public function __construct(?Container $container)
2828
{
2929
$this->container = $container ?: new Container;
3030

tests/Console/CleanEmailsTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ public function setUp(): void
2323
/** @test */
2424
public function it_can_clean_the_statistics()
2525
{
26-
Collection::times(60)->each(function (int $index) {
26+
Collection::times(200)->each(function (int $index) {
2727
InboundEmail::forceCreate([
2828
'message' => Str::random(),
2929
'created_at' => Carbon::now()->subDays($index)->startOfDay(),
3030
]);
3131
});
3232

33-
$this->assertCount(60, InboundEmail::all());
33+
$this->assertCount(200, InboundEmail::all());
3434

3535
Artisan::call('mailbox:clean');
3636

@@ -46,19 +46,19 @@ public function it_errors_if_max_age_inf()
4646
{
4747
$this->app['config']->set('mailbox.store_incoming_emails_for_days', INF);
4848

49-
Collection::times(60)->each(function (int $index) {
49+
Collection::times(200)->each(function (int $index) {
5050
InboundEmail::forceCreate([
5151
'message' => Str::random(),
5252
'created_at' => Carbon::now()->subDays($index)->startOfDay(),
5353
]);
5454
});
5555

56-
$this->assertCount(60, InboundEmail::all());
56+
$this->assertCount(200, InboundEmail::all());
5757

5858
$this->artisan('mailbox:clean')
5959
->expectsOutput('mailbox:clean is disabled because store_incoming_emails_for_days is set to INF.')
6060
->assertExitCode(1);
6161

62-
$this->assertCount(60, InboundEmail::all());
62+
$this->assertCount(200, InboundEmail::all());
6363
}
6464
}

0 commit comments

Comments
 (0)