From ea9a275a006a2f09efb57ccbdeae01a312499f8b Mon Sep 17 00:00:00 2001 From: APTX Date: Tue, 18 Aug 2015 22:13:10 +0200 Subject: [PATCH] Take pending MyList updates into account when choosing the first unwatched file. Pending MyList update changes are only written to the my_* fields when a the UDP API confirms it's been set. If the UDP API doesn't work for some reason firstUnwatchedByAid will keep returning the same file until AniDB confirms the change. To work around this, firstUnwatchedByAid now checks if a file isn't queued to be marked watched right now (an update without a finished time set). If it is, the file is treated as watched. This only works in the simple case where a file is marked watched by fid. It's the method MyList::markWatched uses. All other methods aren't available outside of manually preparing a PendingMyListUpdate. --- localmylist/database.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/localmylist/database.cpp b/localmylist/database.cpp index 270b482..5189345 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -343,19 +343,25 @@ 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, " - " 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 episode_type et ON et.type = e.type " - " LEFT JOIN file_location fl ON fl.fid = f.fid " - " WHERE f.my_watched IS NULL " - " 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 et.ordering ASC, e.epno ASC, pixels DESC, f.version DESC "); + QSqlQuery &q = prepare(R"( + 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 episode_type et ON et.type = e.type + LEFT JOIN file_location fl ON fl.fid = f.fid + WHERE f.my_watched IS NULL + 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) + AND NOT EXISTS (SELECT 1 FROM pending_mylist_update pmu + WHERE pmu.finished IS NULL + AND pmu.set_my_watched = true + AND pmu.my_watched IS NOT NULL + AND pmu.fid = f.fid) + ORDER BY et.ordering ASC, e.epno ASC, pixels DESC, f.version DESC + )"); q.bindValue(":aid", aid); return readOpenFileData(q); -- 2.52.0