Merge pull request #580 from TeamPiped/fast-video-checks

Faster checks for video exists.
This commit is contained in:
Kavin 2023-04-29 20:07:53 +01:00 committed by GitHub
commit 7dc0afa966
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,12 +97,11 @@ public class DatabaseHelper {
} }
public static boolean doesVideoExist(SharedSessionContract s, String id) { public static boolean doesVideoExist(SharedSessionContract s, String id) {
CriteriaBuilder cb = s.getCriteriaBuilder(); return s.createQuery("SELECT 1 FROM Video WHERE id = :id", Integer.class)
CriteriaQuery<String> cr = cb.createQuery(String.class); .setParameter("id", id)
Root<Video> root = cr.from(Video.class); .setMaxResults(1)
cr.select(root.get("id")).where(cb.equal(root.get("id"), id)); .uniqueResultOptional()
.isPresent();
return s.createQuery(cr).uniqueResult() != null;
} }
public static PlaylistVideo getPlaylistVideoFromId(SharedSessionContract s, String id) { public static PlaylistVideo getPlaylistVideoFromId(SharedSessionContract s, String id) {