]> Some of my projects - localmylist.git/commitdiff
Report data errors.
authorAPTX <marek321@gmail.com>
Wed, 15 May 2013 15:11:03 +0000 (17:11 +0200)
committerAPTX <marek321@gmail.com>
Wed, 15 May 2013 15:11:03 +0000 (17:11 +0200)
localmylist/database.cpp
localmylist/database.h
localmylist/requesthandler.cpp

index 98201b28927a739d421aaf3ab00ec45f3cecaef4..43463fa9caa74137ca26dfc70f0660c2e16e3233 100644 (file)
@@ -1325,6 +1325,26 @@ bool Database::failPendingRequestsFromOldClients()
        return exec(q);
 }
 
+bool Database::pendingRequestDataError(const PendingRequest &request)
+{
+       QSqlQuery &q = prepare(
+       "UPDATE pending_request "
+       "       SET connection_error_count = 0, data_error_count = data_error_count + 1 "
+       "       WHERE aid = :aid "
+       "               AND eid = :eid "
+       "               AND fid = :fid "
+       "               AND ed2k = :ed2k "
+       "               AND size = :size ");
+
+       q.bindValue(":aid", request.aid);
+       q.bindValue(":eid", request.eid);
+       q.bindValue(":fid", request.fid);
+       q.bindValue(":ed2k", (request.ed2k.isNull() ? QByteArray("") : request.ed2k).constData());
+       q.bindValue(":size", request.size);
+
+       return exec(q);
+}
+
 bool Database::clearStartedPendingRequests()
 {
        return exec(
index 5cc464d5263ad31d5ba3422fac9b1d25e241309e..5c71cc009a5fd1195921a51718af01d995a8b525 100644 (file)
@@ -110,6 +110,8 @@ public slots:
        bool removeReport(int reportId);
 
        bool failPendingRequestsFromOldClients();
+       bool pendingRequestDataError(const PendingRequest &request);
+
        bool clearStartedPendingRequests();
        bool clearStartedMyListUpdateRequests();
        bool clearFileRenames();
index 09653afa649ceac1d03288011037cdfc9afeacc2..f634a02f4e884dffeacafe32142cb6b620df3095 100644 (file)
@@ -221,10 +221,17 @@ void RequestHandler::animeRequestComplete(bool success)
        Q_ASSERT(reply);
        reply->deleteLater();
 
+       RaiiTransaction t(db);
+       t.commit();
+
        if (!success)
+       {
+               PendingRequest r;
+               r.aid = reply->command().aid();
+               db->pendingRequestDataError(r);
                return;
+       }
 
-       db->transaction();
        // If entry exists we get to update fields we know.
        // Entry might exist just with my values and aid from vote command
        Anime next = db->getAnime(reply->command().aid());
@@ -255,7 +262,6 @@ void RequestHandler::animeRequestComplete(bool success)
                db->addAnime(next);
        else
                db->setAnime(next);
-       db->commit();
 
        // my values obtained with VoteCommand
 
@@ -275,10 +281,17 @@ void RequestHandler::episodeRequestComplete(bool success)
        Q_ASSERT(reply);
        reply->deleteLater();
 
+       RaiiTransaction t(db);
+       t.commit();
+
        if (!success)
+       {
+               PendingRequest r;
+               r.eid = reply->command().eid();
+               db->pendingRequestDataError(r);
                return;
+       }
 
-       db->transaction();
        Episode next = db->getEpisode(reply->command().eid());
 
        bool isNew = !next.eid;
@@ -305,7 +318,6 @@ void RequestHandler::episodeRequestComplete(bool success)
                db->addEpisode(next);
        else
                db->setEpisode(next);
-       db->commit();
 
        // Obtain my values
        VoteReply *voteReply = Client::instance()->send(VoteCommand(VoteCommand::AnimeVote, next.aid, VoteCommand::Retrieve, reply->epnoAsInt()));
@@ -324,10 +336,31 @@ void RequestHandler::fileRequestComplete(bool success)
        Q_ASSERT(reply);
        reply->deleteLater();
 
+       RaiiTransaction t(db);
+       t.commit();
+
        if (!success)
+       {
+               PendingRequest r;
+
+               if (reply->command().fid())
+               {
+                       r.fid = reply->command().fid();
+               }
+               else if (!reply->command().ed2k().isEmpty())
+               {
+                       r.ed2k = reply->command().ed2k();
+                       r.size = reply->command().size();
+               }
+               else
+               {
+                       Q_ASSERT_X(false, "Request Handler", "Filerequest with no fid/ed2k&size");
+               }
+
+               db->pendingRequestDataError(r);
                return;
+       }
 
-       db->transaction();
        // Fid might not be known in command
        File next = db->getFile(reply->fid());
 
@@ -419,8 +452,6 @@ void RequestHandler::fileRequestComplete(bool success)
                }
        }
 
-       db->commit();
-
        if (addedNewRequest)
                emit batchFinished();
 
@@ -537,11 +568,18 @@ void RequestHandler::myListAddReplyRecieved(bool success)
        Q_ASSERT(reply);
        reply->deleteLater();
 
+       RaiiTransaction t(db);
+       t.commit();
+
        if (!success)
+       {
+               PendingRequest r;
+               r.fid = reply->command().fid();
+               db->pendingRequestDataError(r);
                return;
+       }
 
-       db->transaction();
-
+       // TODO is this if necessary?
        if (reply->command().fid())
        {
                File f = db->getFile(reply->command().fid());