Check-in [23c8dad306]
Not logged in
Overview

SHA1 Hash:23c8dad306718247d2abbc88c6a255c49ba1a460
Date: 2007-07-30 05:17:44
User: dan
Comment:Delete records from the temporary table "pending" after sending them.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/xfer.c from [1d5b7d85e6] to [ccedc94bf2].

@@ -129,10 +129,11 @@
 
 /*
 ** Send all pending files.
 */
 static int send_all_pending(Blob *pOut){
+  int iRidSent = 0;
   int sent = 0;
   int nSent = 0;
   int maxSize = db_get_int("http-msg-size", 1000000);
   Stmt q;
 #if 0
@@ -156,16 +157,17 @@
       " SELECT rid FROM delta WHERE srcid=%d",
       rid, rid
     );
   }
 #endif
-  db_prepare(&q, "SELECT rid FROM pending");
+  db_prepare(&q, "SELECT rid FROM pending ORDER BY rid");
   while( db_step(&q)==SQLITE_ROW ){
     int rid = db_column_int(&q, 0);
     if( sent<maxSize ){
       sent += send_file(rid, pOut);
       nSent++;
+      iRidSent = rid;
     }else{
       char *zUuid = db_text(0,
                       "SELECT uuid FROM blob WHERE rid=%d AND size>=0", rid);
       if( zUuid ){
         if( pOut ){
@@ -176,10 +178,17 @@
         free(zUuid);
       }
     }
   }
   db_finalize(&q);
+
+  /* Delete the 'pending' records for all files just sent. Otherwise,
+  ** we can wind up sending some files more than once.
+  */
+  if( nSent>0 ){
+    db_multi_exec("DELETE FROM pending WHERE rid <= %d", iRidSent);
+  }
 
 #if 0
   db_multi_exec("DROP TABLE priority");
 #endif
   return nSent;