diff options
author | Gabriel Ivascu <gabrielivascu@gnome.org> | 2017-12-01 22:14:11 +0200 |
---|---|---|
committer | Gabriel Ivascu <gabrielivascu@gnome.org> | 2017-12-02 00:35:51 +0200 |
commit | d65dde74838ade3e0dc81779312ca1c2f5cb391d (patch) | |
tree | 5508f65d74482d1ff51c21e834041b12f0dbbe37 | |
parent | 8969027196ef3b20b24a9f4fccec091f6db4de76 (diff) | |
download | epiphany-wip/sync-batch-upload.tar.gz |
sync-service: Signal finish when last batch from last collection is committedwip/sync-batch-upload
-rw-r--r-- | lib/sync/ephy-sync-service.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c index 242f8fce5..9464e4b10 100644 --- a/lib/sync/ephy-sync-service.c +++ b/lib/sync/ephy-sync-service.c @@ -138,6 +138,7 @@ typedef struct { guint end; char *batch_id; gboolean batch_is_last; + gboolean sync_done; } BatchUploadAsyncData; static StorageRequestAsyncData * @@ -285,7 +286,8 @@ batch_upload_async_data_new (EphySyncService *service, guint start, guint end, const char *batch_id, - gboolean batch_is_last) + gboolean batch_is_last, + gboolean sync_done) { BatchUploadAsyncData *data; @@ -297,6 +299,7 @@ batch_upload_async_data_new (EphySyncService *service, data->end = end; data->batch_id = g_strdup (batch_id); data->batch_is_last = batch_is_last; + data->sync_done = sync_done; return data; } @@ -308,7 +311,8 @@ batch_upload_async_data_dup (BatchUploadAsyncData *data) return batch_upload_async_data_new (data->service, data->manager, data->synchronizables, data->start, - data->end, data->batch_id, data->batch_is_last); + data->end, data->batch_id, + data->batch_is_last, data->sync_done); } static inline void @@ -1352,15 +1356,15 @@ commit_batch_cb (SoupSession *session, if (msg->status_code != 200) { g_warning ("Failed to commit batch. Status code: %u, response: %s", msg->status_code, msg->response_body->data); - goto out; + } else { + LOG ("Successfully committed batches"); + /* Update sync time. */ + last_modified = soup_message_headers_get_one (msg->response_headers, "X-Last-Modified"); + ephy_synchronizable_manager_set_sync_time (data->manager, g_ascii_strtod (last_modified, NULL)); } - LOG ("Successfully committed batches"); - /* Update sync time. */ - last_modified = soup_message_headers_get_one (msg->response_headers, "X-Last-Modified"); - ephy_synchronizable_manager_set_sync_time (data->manager, g_ascii_strtod (last_modified, NULL)); - -out: + if (data->sync_done) + g_signal_emit (data->service, signals[SYNC_FINISHED], 0); batch_upload_async_data_free (data); } @@ -1464,8 +1468,11 @@ merge_collection_finished_cb (GPtrArray *to_upload, const char *collection; char *endpoint = NULL; - if (!to_upload || to_upload->len == 0) + if (!to_upload || to_upload->len == 0) { + if (data->is_last) + g_signal_emit (data->service, signals[SYNC_FINISHED], 0); goto out; + } collection = ephy_synchronizable_manager_get_collection_name (data->manager); endpoint = g_strdup_printf ("storage/%s?batch=true", collection); @@ -1475,7 +1482,8 @@ merge_collection_finished_cb (GPtrArray *to_upload, bdata = batch_upload_async_data_new (data->service, data->manager, to_upload, i, MIN (i + step, to_upload->len), - NULL, FALSE); + NULL, FALSE, + data->is_last && i + step >= to_upload->len); ephy_sync_service_queue_storage_request (data->service, endpoint, SOUP_METHOD_POST, "[]", -1, -1, start_batch_upload_cb, bdata); @@ -1483,8 +1491,6 @@ merge_collection_finished_cb (GPtrArray *to_upload, out: g_free (endpoint); - if (data->is_last) - g_signal_emit (data->service, signals[SYNC_FINISHED], 0); sync_collection_async_data_free (data); } |