Skip to content

Commit 330c239

Browse files
committed
no n+1 and simplier migration
1 parent 3c4f91f commit 330c239

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

app/Services/Servers/ServerDeletionService.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ public function handle(Server $server): void
7878
}
7979

8080
// clear any allocation notes for the server
81-
$server->allocations->each(function ($allocation) {
82-
$allocation->update(['notes' => null]);
83-
});
81+
$server->allocations()->update(['notes' => null]);
82+
8483

8584
$server->delete();
8685
});

database/migrations/2024_07_13_091852_clear_unused_allocation_notes.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
*/
1111
public function up(): void
1212
{
13+
1314
DB::table('allocations')
14-
->where('server_id', null)
15-
->whereNot('notes', null)
15+
->whereNull('server_id')
1616
->update(['notes' => null]);
17+
1718
}
1819

1920
/**

0 commit comments

Comments
 (0)