]> Some of my projects - localmylist.git/commitdiff
Add new columns to pending_request.
authorAPTX <redacted>
Mon, 13 May 2013 20:04:10 +0000 (22:04 +0200)
committerAPTX <redacted>
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 f3c47f4..98201b2 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 cf4b5a9..5cc464d 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 1f14245..703ffe4 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 83245cd..912a6dc 100644 (file)
@@ -164,6 +164,11 @@ struct LOCALMYLISTSHARED_EXPORT PendingRequest
        QByteArray ed2k;
        qint64 size;
 
+       int clientId;
+       int priority;
+       int connectionFailCount;
+       int dataFailCount;
+
        PendingRequest();
 };
 
index 90903af..4a517e4 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);