]> Some of my projects - localmylist.git/commitdiff
Add new columns to pending_request.
authorAPTX <marek321@gmail.com>
Mon, 13 May 2013 20:04:10 +0000 (22:04 +0200)
committerAPTX <marek321@gmail.com>
Mon, 13 May 2013 20:04:10 +0000 (22:04 +0200)
localmylist/database.cpp
localmylist/database.h
localmylist/databaseclasses.cpp
localmylist/databaseclasses.h
localmylist/share/schema/schema.sql

index f3c47f4bb4c95293714046f73e82c00337baae95..98201b28927a739d421aaf3ab00ec45f3cecaef4 100644 (file)
@@ -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<PendingRequest> 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<PendingRequest> 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");
index cf4b5a97aba6377fe017f6bca451df5a0a433fde..5cc464d5263ad31d5ba3422fac9b1d25e241309e 100644 (file)
@@ -109,6 +109,7 @@ public slots:
        bool setReport(const LocalMyList::Report &report);
        bool removeReport(int reportId);
 
+       bool failPendingRequestsFromOldClients();
        bool clearStartedPendingRequests();
        bool clearStartedMyListUpdateRequests();
        bool clearFileRenames();
index 1f142453b4d31a074abe7315bab9ed51f970a9ea..703ffe41546a644460adb1203e29c465ae51b12f 100644 (file)
@@ -84,6 +84,11 @@ PendingRequest::PendingRequest()
        eid = 0;
        fid = 0;
        size = 0;
+
+       clientId = 0;
+       priority = 0;
+       connectionFailCount = 0;
+       dataFailCount = 0;
 }
 
 PendingMyListUpdate::PendingMyListUpdate()
index 83245cdc3f70b83bd0244c044ad75b885dbdbdc8..912a6dc2ae324c39d62ba7a66149cecaaf2cf30d 100644 (file)
@@ -164,6 +164,11 @@ struct LOCALMYLISTSHARED_EXPORT PendingRequest
        QByteArray ed2k;
        qint64 size;
 
+       int clientId;
+       int priority;
+       int connectionFailCount;
+       int dataFailCount;
+
        PendingRequest();
 };
 
index 90903af947ddd7f41dde48ee8c2300da88ff8f88..4a517e41f5fbf70e3e7bffe839d01a55a56ec5ff 100644 (file)
@@ -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);