Skip to content

Commit

Permalink
Merge pull request #453 from pbogre/remove-movie-duplicates
Browse files Browse the repository at this point in the history
remove duplicate movies in "all movies"
  • Loading branch information
leepeuker authored Jul 28, 2023
2 parents fd3c540 + d1a95d4 commit 8a3207a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Domain/Movie/MovieRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,18 @@ public function fetchUniqueMoviesPaginated(

return $this->dbConnection->fetchAllAssociative(
<<<SQL
SELECT m.*, mur.rating as userRating
FROM movie m
JOIN movie_user_watch_dates mh on mh.movie_id = m.id and mh.user_id = ?
LEFT JOIN movie_user_rating mur ON mh.movie_id = mur.movie_id and mur.user_id = ?
LEFT JOIN movie_genre mg on m.id = mg.movie_id
LEFT JOIN genre g on mg.genre_id = g.id
$whereQuery
GROUP BY m.id, title, release_date, watched_at, rating
ORDER BY $sortBySanitized $sortOrder, title asc
SELECT * FROM (
SELECT m.*, mur.rating as userRating, ROW_NUMBER() OVER(PARTITION BY m.id) rn
FROM movie m
JOIN movie_user_watch_dates mh on mh.movie_id = m.id and mh.user_id = ?
LEFT JOIN movie_user_rating mur on mh.movie_id = mur.movie_id and mh.user_id = ?
LEFT JOIN movie_genre mg on m.id = mg.movie_id
LEFT JOIN genre g on mg.genre_id = g.id
$whereQuery
GROUP BY m.id, title, release_date, watched_at, rating
ORDER BY $sortBySanitized $sortOrder, title asc
) a
WHERE rn = 1
LIMIT $offset, $limit
SQL,
$payload,
Expand Down

0 comments on commit 8a3207a

Please sign in to comment.