From: APTX Date: Wed, 15 May 2013 15:11:03 +0000 (+0200) Subject: Report data errors. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=4006e8aac4881fb5030e64455cbe8879dd788925;p=localmylist.git Report data errors. --- diff --git a/localmylist/database.cpp b/localmylist/database.cpp index 98201b2..43463fa 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -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( diff --git a/localmylist/database.h b/localmylist/database.h index 5cc464d..5c71cc0 100644 --- a/localmylist/database.h +++ b/localmylist/database.h @@ -110,6 +110,8 @@ public slots: bool removeReport(int reportId); bool failPendingRequestsFromOldClients(); + bool pendingRequestDataError(const PendingRequest &request); + bool clearStartedPendingRequests(); bool clearStartedMyListUpdateRequests(); bool clearFileRenames(); diff --git a/localmylist/requesthandler.cpp b/localmylist/requesthandler.cpp index 09653af..f634a02 100644 --- a/localmylist/requesthandler.cpp +++ b/localmylist/requesthandler.cpp @@ -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());