csync_update: Don't fetch the etag in the local discovery from the DB
authorOlivier Goffart <ogoffart@woboq.com>
Wed, 21 Oct 2015 12:17:30 +0000 (14:17 +0200)
committerOlivier Goffart <ogoffart@woboq.com>
Wed, 21 Oct 2015 14:38:26 +0000 (16:38 +0200)
We don't need it, and it's slow.
This saves a lot of DB queries

(Also replaced a strlen>0 with a faster check)

csync/src/csync_statedb.c
csync/src/csync_update.c
src/libsync/syncengine.cpp
test/testcsyncsqlite.h

index f12e0b161a6a6be0167e2f4c1ae0e49e545cef32..92ca528b66cadcf89a844a764bc5aa1beae328b7 100644 (file)
@@ -416,28 +416,6 @@ csync_file_stat_t *csync_statedb_get_stat_by_inode(CSYNC *ctx,
   return st;
 }
 
-/* Get the etag. */
-char *csync_statedb_get_etag( CSYNC *ctx, uint64_t jHash ) {
-    char *ret = NULL;
-    csync_file_stat_t *fs = NULL;
-
-    if( !ctx ) {
-        return NULL;
-    }
-
-    if( ! csync_get_statedb_exists(ctx)) return ret;
-
-    fs = csync_statedb_get_stat_by_hash(ctx, jHash );
-    if( fs ) {
-        if( fs->etag ) {
-            ret = c_strdup(fs->etag);
-        }
-        csync_file_stat_free(fs);
-    }
-
-    return ret;
-}
-
 #define BELOW_PATH_QUERY "SELECT phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote FROM metadata WHERE pathlen>? AND path LIKE(?)"
 
 int csync_statedb_get_below_path( CSYNC *ctx, const char *path ) {
index 99570c2320bb8b5bc738dc43f4aa72e9dc17c86a..4eb0457f726ca3f4e9b52f0a3888686cc94d471d 100644 (file)
@@ -270,10 +270,6 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
                   ((int64_t) fs->mtime), ((int64_t) tmp->modtime),
                   fs->etag, tmp->etag, (uint64_t) fs->inode, (uint64_t) tmp->inode,
                   (uint64_t) fs->size, (uint64_t) tmp->size, fs->remotePerm, tmp->remotePerm, tmp->has_ignored_files );
-        if( !fs->etag) {
-            st->instruction = CSYNC_INSTRUCTION_EVAL;
-            goto out;
-        }
         if((ctx->current == REMOTE_REPLICA && !c_streq(fs->etag, tmp->etag ))
             || (ctx->current == LOCAL_REPLICA && (!_csync_mtime_equal(fs->mtime, tmp->modtime)
                                                   // zero size in statedb can happen during migration
@@ -772,31 +768,6 @@ int csync_ftw(CSYNC *ctx, const char *uri, csync_walker_fn fn,
       flag = CSYNC_FTW_FLAG_NSTAT;
     }
 
-    if( ctx->current == LOCAL_REPLICA ) {
-        char *etag = NULL;
-        int len = strlen( path );
-        uint64_t h = c_jhash64((uint8_t *) path, len, 0);
-        etag = csync_statedb_get_etag( ctx, h );
-
-        if(_last_db_return_error(ctx)) {
-            ctx->status_code = CSYNC_STATUS_UNSUCCESSFUL;
-            SAFE_FREE(etag);
-            goto error;
-        }
-
-        if( etag ) {
-            SAFE_FREE(fs->etag);
-            fs->etag = etag;
-            fs->fields |= CSYNC_VIO_FILE_STAT_FIELDS_ETAG;
-
-            if( c_streq(etag, "")) {
-                CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Uniq ID from Database is EMPTY: %s", path);
-            } else {
-                CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "Uniq ID from Database: %s -> %s", path, fs->etag ? fs->etag : "<NULL>" );
-            }
-        }
-    }
-
     previous_fs = ctx->current_fs;
 
     /* Call walker function for each file */
index ca2f8ff7c99966a3ecede60d7400e5cbba8aebc6..0588364bb7097622d68c843b9634020f12f3a65b 100644 (file)
@@ -341,7 +341,7 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
         }
     }
 
-    if (file->file_id && strlen(file->file_id) > 0) {
+    if (file->file_id && file->file_id[0]) {
         item->_fileId = file->file_id;
     }
     if (file->directDownloadUrl) {
@@ -431,9 +431,9 @@ int SyncEngine::treewalkFile( TREE_WALK_FILE *file, bool remote )
 
     item->_isDirectory = file->type == CSYNC_FTW_TYPE_DIR;
 
-    // The etag is already set in the previous sync phases somewhere. Maybe we should remove it there
-    // and do it here so we have a consistent state about which tree stores information from which source.
-    item->_etag = file->etag;
+    if (file->etag && file->etag[0]) {
+        item->_etag = file->etag;
+    }
     item->_size = file->size;
 
     if (!remote) {
index 01b886b6de98ebe1f8086ebc2fdab71086b7ff7f..be7b5563a0e1435af21ce9d7e1b390e17572780c 100644 (file)
@@ -81,16 +81,6 @@ private slots:
         csync_file_stat_free(st);
     }
 
-    void testEtag() {
-        char *etag = csync_statedb_get_etag((CSYNC*)(&_ctx), 7145399680328529363 );
-        QCOMPARE( QString::fromUtf8(etag), QLatin1String("52847f208be09"));
-        SAFE_FREE(etag);
-
-        etag = csync_statedb_get_etag((CSYNC*)(&_ctx), -8148768149813301136);
-        QCOMPARE( QString::fromUtf8(etag), QLatin1String("530d148493894"));
-        SAFE_FREE(etag);
-    }
-
     void cleanupTestCase() {
         SAFE_FREE(_ctx.statedb.file);
         csync_statedb_close((CSYNC*)(&_ctx));