Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: use subquery to avoid too many placeholders when deleting albums…
… with many photos

Co-authored-by: ildyria <627094+ildyria@users.noreply.github.com>
Agent-Logs-Url: https://github.com/LycheeOrg/Lychee/sessions/4ddd5192-7894-4390-85ae-d0eaf37842db
  • Loading branch information
Copilot and ildyria committed Mar 24, 2026
commit 5bb4fd9d160cd3a8b002d60008ee782624cc80fc
11 changes: 7 additions & 4 deletions app/Actions/Album/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ public function findAllPhotosToDelete(array $album_ids): PhotosToBeDeletedDTO
->orderBy(PA::PHOTO_ID, 'asc')
->get();

// Potential photos to be deleted
$photos_ids = $photos_ids_occurances_in_album->pluck('photo_id')->all();

// We select all the photos which are impacted: we want to know if they are only occuring in those albums or not.
// Note that photos which are only in the deleted albums can be deleted fully.
// We use a subquery instead of whereIn($photos_ids) to avoid hitting the database
// placeholder limit (MySQL error 1390) when there are many photos to delete.
/** @var Collection<int,object{photo_id:string,album_count:int}> $photos_ids_occurances */
$photos_ids_occurances = DB::table(PA::PHOTO_ALBUM)
->whereIn(PA::PHOTO_ID, $photos_ids)
->whereIn(PA::PHOTO_ID, function ($query) use ($album_ids): void {
$query->select(PA::PHOTO_ID)
->from(PA::PHOTO_ALBUM)
->whereIn(PA::ALBUM_ID, $album_ids);
})
->select([PA::PHOTO_ID, DB::raw('COUNT(*) AS album_count')])
->groupBy(PA::PHOTO_ID)
->orderBy(PA::PHOTO_ID, 'asc')
Expand Down
Loading