Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/Actions/Album/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Query\Builder as BaseBuilder;
use Illuminate\Support\Facades\DB;
use Safe\Exceptions\ArrayException;

/**
Expand Down Expand Up @@ -87,7 +88,7 @@ public function do(array $album_ids): FileDeleter
/** @var Collection<int,Album> $albums */
/** @phpstan-ignore varTag.type (False positive, NestedSetCollection requires Eloquent Collection) */
$albums = Album::query()
->without(['cover', 'thumb', 'min_privilege_cover', 'max_privilege_cover'])
->without(['cover', 'thumb', 'min_privilege_cover', 'max_privilege_cover', 'owner', 'access_permissions', 'statistics'])
->select(['id', 'parent_id', '_lft', '_rgt', 'track_short_path'])
->findMany($album_ids);

Expand All @@ -100,7 +101,11 @@ public function do(array $album_ids): FileDeleter
/** @var Album $album */
foreach ($albums as $album) {
// Collect all (aka recursive) sub-albums in each album
$sub_albums = $album->descendants()->getQuery()->without(['cover', 'thumb', 'min_privilege_cover', 'max_privilege_cover'])->select(['id', 'track_short_path'])->get();
// Use DB::table directly to avoid any Eloquent overhead and eager loading
$sub_albums = DB::table('albums')
->select(['id', 'track_short_path'])
->whereBetween('_lft', [$album->_lft + 1, $album->_rgt - 1])
->get();
$recursive_album_ids = array_merge($recursive_album_ids, $sub_albums->pluck('id')->all());
$recursive_album_tracks = $recursive_album_tracks->merge($sub_albums->pluck('track_short_path'));
}
Expand Down
Loading