Skip to content

Commit 1b48b0b

Browse files
committed
fix(network): added early return for empty-db case: when there's no payload AND db_version == 0.
1. Added early return for empty-db case (lines 959–966): When there's no payload (blob == NULL || blob_size == 0) AND db_version == 0, skip the network call entirely and return { server_version: 0, local_version: 0, status: "synced" }. This avoids the 404 from the status endpoint when the server doesn't know the device yet. 2. Fixed condition from || to && (line 969): Changed blob != NULL || blob_size > 0 to blob != NULL && blob_size > 0 — both conditions must be true to confirm there's actual data to upload.
1 parent da4387d commit 1b48b0b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/network.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,18 @@ int cloudsync_network_send_changes_internal (sqlite3_context *context, int argc,
956956
return rc;
957957
}
958958

959+
// Case 1: empty local db — no payload and no server state, skip network entirely
960+
if ((blob == NULL || blob_size == 0) && db_version == 0) {
961+
if (out) {
962+
out->server_version = 0;
963+
out->local_version = 0;
964+
out->status = network_compute_status(0, 0, 0, 0);
965+
}
966+
return SQLITE_OK;
967+
}
968+
959969
NETWORK_RESULT res;
960-
if (blob != NULL || blob_size > 0) {
970+
if (blob != NULL && blob_size > 0) {
961971
// there is data to send
962972
res = network_receive_buffer(netdata, netdata->upload_endpoint, netdata->authentication, true, false, NULL, CLOUDSYNC_HEADER_SQLITECLOUD);
963973
if (res.code != CLOUDSYNC_NETWORK_BUFFER) {

0 commit comments

Comments
 (0)