Merge pull request #452 from TeamPiped/playlist-opt

Simplify and optimize playlist query.
This commit is contained in:
Kavin 2022-11-18 21:51:36 +00:00 committed by GitHub
commit da67e0e714
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -142,15 +142,10 @@ public class DatabaseHelper {
CriteriaBuilder cb = s.getCriteriaBuilder();
CriteriaQuery<PlaylistVideo> cr = cb.createQuery(PlaylistVideo.class);
var root = cr.from(PlaylistVideo.class);
root.fetch("channel", JoinType.RIGHT);
cr.select(root);
var sq = cr.subquery(String.class);
{
var sqRoot = sq.from(Playlist.class);
sq.select(sqRoot.get("videos").get("id"))
.where(cb.equal(sqRoot.get("playlist_id"), UUID.fromString(id)));
}
cr.where(root.get("id").in(sq));
root.fetch("channel", JoinType.LEFT);
var plRoot = cr.from(Playlist.class);
cr.where(cb.equal(plRoot.get("playlist_id"), UUID.fromString(id)));
return s.createQuery(cr).list();
}