From: APTX Date: Sat, 25 May 2013 20:51:46 +0000 (+0200) Subject: Add failed column to pending_request marking that a request failed with a data error. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=d4abecbddfa0276b3423cf27eed7143d56a6b882;p=localmylist.git Add failed column to pending_request marking that a request failed with a data error. A connection error is no reply in x time, while data errors have to be retried after x time. --- diff --git a/anioni/anioni.cpp b/anioni/anioni.cpp index a5eecfd..f2de4fd 100644 --- a/anioni/anioni.cpp +++ b/anioni/anioni.cpp @@ -69,7 +69,7 @@ void AniOni::handleUdpClientError() void AniOni::failRequests() { log("Clearing failed Requests", QtServiceBase::Information); - LocalMyList::instance()->database()->clearFailedPendingRequests(); + LocalMyList::instance()->database()->clearPendingRequestConnectionErrors(); LocalMyList::instance()->database()->clearFailedPendingMyListUpdateRequests(); } diff --git a/localmylist-management/mainwindow.cpp b/localmylist-management/mainwindow.cpp index 4c69901..4aaaaed 100644 --- a/localmylist-management/mainwindow.cpp +++ b/localmylist-management/mainwindow.cpp @@ -268,7 +268,7 @@ void MainWindow::on_actionClearAnimeTitleData_triggered() void MainWindow::on_actionClearFailedRequests_triggered() { - LocalMyList::instance()->database()->clearFailedPendingRequests(); + LocalMyList::instance()->database()->clearPendingRequestConnectionErrors(); LocalMyList::instance()->database()->clearFailedPendingMyListUpdateRequests(); } diff --git a/localmylist/database.cpp b/localmylist/database.cpp index 43463fa..6e9f434 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -1022,7 +1022,7 @@ bool Database::addRequest(const PendingRequest &request) { QSqlQuery &q = prepare( "INSERT INTO pending_request VALUES(:aid, :eid, :fid, " - " :ed2k, :size, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) "); + " :ed2k, :size, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) "); q.bindValue(":aid", request.aid); q.bindValue(":eid", request.eid); @@ -1041,6 +1041,7 @@ QList Database::getRequestBatch(int limit) " (SELECT aid, eid, fid, ed2k, size FROM pending_request " " WHERE start IS NULL " " AND data_error_count <= 10 " + " AND failed IS NULL " " ORDER BY priority DESC, added ASC " " LIMIT :limit) " " RETURNING aid, eid, fid, ed2k, size "); @@ -1055,6 +1056,7 @@ QList Database::getRequestBatch(int limit) while (q.next()) { + // TODO add readPendingRequest method PendingRequest request; request.aid = q.value(0).toInt(); request.eid = q.value(1).toInt(); @@ -1329,7 +1331,7 @@ bool Database::pendingRequestDataError(const PendingRequest &request) { QSqlQuery &q = prepare( "UPDATE pending_request " - " SET connection_error_count = 0, data_error_count = data_error_count + 1 " + " SET connection_error_count = 0, data_error_count = data_error_count + 1, failed = now() " " WHERE aid = :aid " " AND eid = :eid " " AND fid = :fid " @@ -1375,13 +1377,14 @@ bool Database::clearFailedFileRenames() "WHERE failed_rename = true"); } -bool Database::clearFailedPendingRequests(int minutes) +bool Database::clearPendingRequestConnectionErrors(int minutes) { QSqlQuery &q = prepare( "UPDATE pending_request " " SET start = NULL, connection_error_count = connection_error_count + 1 " " WHERE start IS NOT NULL " - " AND age(current_timestamp, start) > :interval "); + " AND age(current_timestamp, start) > :interval " + " AND failed IS NULL "); q.bindValue(":interval", QString::number(minutes) + " minutes"); return exec(q); diff --git a/localmylist/database.h b/localmylist/database.h index 5c71cc0..4d3585f 100644 --- a/localmylist/database.h +++ b/localmylist/database.h @@ -117,7 +117,7 @@ public slots: bool clearFileRenames(); bool clearFailedFileRenames(); - bool clearFailedPendingRequests(int minutes = 10); + bool clearPendingRequestConnectionErrors(int minutes = 10); bool clearFailedPendingMyListUpdateRequests(int minutes = 10); bool truncateTitleData(); diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql index 4a517e4..649338f 100644 --- a/localmylist/share/schema/schema.sql +++ b/localmylist/share/schema/schema.sql @@ -201,6 +201,7 @@ CREATE TABLE pending_request ( client_id integer NOT NULL DEFAULT 0, added timestamp without time zone DEFAULT now(), start timestamp without time zone, + failed timestamp without time zone DEFAULT NULL, connection_error_count integer NOT NULL DEFAULT 0, data_error_count integer NOT NULL DEFAULT 0, CONSTRAINT pending_request_pk PRIMARY KEY (aid, eid, fid, ed2k, size)