]> Some of my projects - localmylist.git/commitdiff
Take pending MyList updates into account when choosing the first unwatched file.
authorAPTX <marek321@gmail.com>
Tue, 18 Aug 2015 20:13:10 +0000 (22:13 +0200)
committerAPTX <marek321@gmail.com>
Tue, 18 Aug 2015 20:13:10 +0000 (22:13 +0200)
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

index 270b482cc51894b4a17be4186ecef608447fc45f..51893459805cd9bf2cc268b2afbad2518d1426db 100644 (file)
@@ -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);