From fec7237356b10d6346b8dfd609bb9e73aaf8f7d1 Mon Sep 17 00:00:00 2001 From: APTX Date: Tue, 7 May 2013 22:37:29 +0200 Subject: [PATCH] Prefer the file with the highest version (and pixels) in firstUnwatched* --- localmylist/database.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/localmylist/database.cpp b/localmylist/database.cpp index 32ca5c0..b2a5934 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -104,7 +104,7 @@ OpenFileData Database::firstUnwatchedByExactTitle(const QString &title) " SELECT 1 FROM file f " " JOIN file_episode_rel fer ON fer.eid = e.eid AND f.fid = fer.fid " " WHERE my_watched IS NOT NULL) " - "ORDER BY epno ASC, pixels DESC "); + "ORDER BY epno ASC, pixels DESC, f.version DESC "); q.bindValue(":title", title); return readOpenFileData(q); @@ -136,7 +136,7 @@ OpenFileData Database::firstUnwatchedByTitle(const QString &title) " SELECT 1 FROM file f " " JOIN file_episode_rel fer ON fer.eid = e.eid AND f.fid = fer.fid " " WHERE my_watched IS NOT NULL) " - "ORDER BY epno ASC, pixels DESC "); + "ORDER BY epno ASC, pixels DESC, f.version DESC "); q.bindValue(":fuzzyTitle", "%" + title + "%"); ofd = readOpenFileData(q); @@ -147,7 +147,9 @@ OpenFileData Database::firstUnwatchedByTitle(const QString &title) OpenFileData Database::firstUnwatchedByAid(int aid) { QSqlQuery &q = prepare( - "SELECT f.fid, a.title_romaji, e.title_english, e.epno, fl.path, fl.host_id FROM file f " + "SELECT f.fid, a.title_romaji, e.title_english, e.epno, fl.path, fl.host_id, " + " CASE WHEN split_part(f.resolution, 'x', 1) = '' OR split_part(f.resolution, 'x', 2) = '' THEN 0 ELSE split_part(f.resolution, 'x', 1)::int * split_part(f.resolution, 'x', 2)::int END pixels " + " FROM file f " " LEFT JOIN anime a ON f.aid = a.aid " " LEFT JOIN episode e ON f.eid = e.eid " " LEFT JOIN file_location fl ON fl.fid = f.fid " @@ -155,7 +157,7 @@ OpenFileData Database::firstUnwatchedByAid(int aid) " AND f.aid = :aid " " AND fl.path IS NOT NULL " " AND NOT EXISTS (SELECT 1 FROM file WHERE eid = e.eid AND my_watched IS NOT NULL LIMIT 1) " - "ORDER BY e.epno ASC "); + "ORDER BY e.epno ASC, pixels DESC, f.version DESC "); q.bindValue(":aid", aid); return readOpenFileData(q); -- 2.52.0