From 41ac9706408edb5cd7762961ef34086e6ae681e1 Mon Sep 17 00:00:00 2001 From: APTX Date: Mon, 13 May 2013 22:04:10 +0200 Subject: [PATCH] Add new columns to pending_request. --- localmylist/database.cpp | 27 +++++++++++++++++++++++---- localmylist/database.h | 1 + localmylist/databaseclasses.cpp | 5 +++++ localmylist/databaseclasses.h | 5 +++++ localmylist/share/schema/schema.sql | 4 +++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/localmylist/database.cpp b/localmylist/database.cpp index f3c47f4..98201b2 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) "); + " :ed2k, :size, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) "); q.bindValue(":aid", request.aid); q.bindValue(":eid", request.eid); @@ -1036,16 +1036,17 @@ bool Database::addRequest(const PendingRequest &request) QList Database::getRequestBatch(int limit) { QSqlQuery &q = prepare( - "UPDATE pending_request SET start = NOW() " + "UPDATE pending_request SET start = NOW(), client_id = :clientId " " WHERE (aid, eid, fid, ed2k, size) IN " " (SELECT aid, eid, fid, ed2k, size FROM pending_request " " WHERE start IS NULL " - " AND fail_count <= 3 " + " AND data_error_count <= 10 " " ORDER BY priority DESC, added ASC " " LIMIT :limit) " " RETURNING aid, eid, fid, ed2k, size "); q.bindValue(":limit", limit); + q.bindValue(":clientId", MyList::instance()->udpClientId()); QList ret; @@ -1306,6 +1307,24 @@ bool Database::removeReport(int reportId) return exec(q); } +bool Database::failPendingRequestsFromOldClients() +{ + const int clientId = MyList::instance()->udpClientId(); + + if (!clientId) + return false; + + QSqlQuery &q = prepare( + "UPDATE pending_request " + " SET start = NULL, client_id = 0, " + " connection_error_count = connection_error_count + 1 " + " WHERE start IS NOT NULL " + " AND client_id < :clientId "); + q.bindValue(":clientId", clientId); + + return exec(q); +} + bool Database::clearStartedPendingRequests() { return exec( @@ -1340,7 +1359,7 @@ bool Database::clearFailedPendingRequests(int minutes) { QSqlQuery &q = prepare( "UPDATE pending_request " - " SET start = NULL, fail_count = fail_count + 1 " + " SET start = NULL, connection_error_count = connection_error_count + 1 " " WHERE start IS NOT NULL " " AND age(current_timestamp, start) > :interval "); q.bindValue(":interval", QString::number(minutes) + " minutes"); diff --git a/localmylist/database.h b/localmylist/database.h index cf4b5a9..5cc464d 100644 --- a/localmylist/database.h +++ b/localmylist/database.h @@ -109,6 +109,7 @@ public slots: bool setReport(const LocalMyList::Report &report); bool removeReport(int reportId); + bool failPendingRequestsFromOldClients(); bool clearStartedPendingRequests(); bool clearStartedMyListUpdateRequests(); bool clearFileRenames(); diff --git a/localmylist/databaseclasses.cpp b/localmylist/databaseclasses.cpp index 1f14245..703ffe4 100644 --- a/localmylist/databaseclasses.cpp +++ b/localmylist/databaseclasses.cpp @@ -84,6 +84,11 @@ PendingRequest::PendingRequest() eid = 0; fid = 0; size = 0; + + clientId = 0; + priority = 0; + connectionFailCount = 0; + dataFailCount = 0; } PendingMyListUpdate::PendingMyListUpdate() diff --git a/localmylist/databaseclasses.h b/localmylist/databaseclasses.h index 83245cd..912a6dc 100644 --- a/localmylist/databaseclasses.h +++ b/localmylist/databaseclasses.h @@ -164,6 +164,11 @@ struct LOCALMYLISTSHARED_EXPORT PendingRequest QByteArray ed2k; qint64 size; + int clientId; + int priority; + int connectionFailCount; + int dataFailCount; + PendingRequest(); }; diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql index 90903af..4a517e4 100644 --- a/localmylist/share/schema/schema.sql +++ b/localmylist/share/schema/schema.sql @@ -198,9 +198,11 @@ CREATE TABLE pending_request ( ed2k character(32) DEFAULT ''::bpchar NOT NULL, size bigint DEFAULT 0 NOT NULL, priority integer DEFAULT 1 NOT NULL, + client_id integer NOT NULL DEFAULT 0, added timestamp without time zone DEFAULT now(), start timestamp without time zone, - fail_count integer NOT NULL DEFAULT 0, + 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) ); CREATE INDEX pending_request_added_idx ON pending_request USING btree (added); -- 2.52.0