mirror of
				https://github.com/TeamPiped/Piped-Backend.git
				synced 2024-08-14 23:51:41 +00:00 
			
		
		
		
	Merge pull request #580 from TeamPiped/fast-video-checks
Faster checks for video exists.
This commit is contained in:
		
						commit
						7dc0afa966
					
				
					 1 changed files with 5 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue