From d7fc5f02cfd4424a1f5144b3e0c6482071275362 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Wed, 17 May 2017 02:38:22 +0100 Subject: [PATCH] Fixed race condition in genre deletion --- app/Jobs/DeleteGenre.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Jobs/DeleteGenre.php b/app/Jobs/DeleteGenre.php index 6aed5171..2c5bcd2f 100644 --- a/app/Jobs/DeleteGenre.php +++ b/app/Jobs/DeleteGenre.php @@ -63,14 +63,17 @@ class DeleteGenre extends Job implements ShouldQueue // This is done instead of a single UPDATE query in order to // generate revision logs for the change. - $this->genreToDelete->tracks()->each(function ($track) { - /** @var Track $track */ - - $track->genre_id = $this->destinationGenre->id; - $track->save(); - $track->updateTags(); - }); + $tracks = Track::whereGenreId($this->genreToDelete->id)->get(); $this->genreToDelete->delete(); + $chunks = $tracks->chunk(200); + + foreach ($chunks as $chunk) { + foreach ($chunk as $track) { + $track->genre_id = $this->destinationGenre->id; + $track->save(); + $track->updateTags(); + } + } } }