Faster checks for video exists.

This commit is contained in:
Kavin 2023-04-29 20:05:21 +01:00
parent c9cfd69953
commit 7f117f572f
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

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