diff --git a/src/realm/sync/noinst/pending_bootstrap_store.cpp b/src/realm/sync/noinst/pending_bootstrap_store.cpp index 03667c58c00..680e1e6e28d 100644 --- a/src/realm/sync/noinst/pending_bootstrap_store.cpp +++ b/src/realm/sync/noinst/pending_bootstrap_store.cpp @@ -141,44 +141,39 @@ void PendingBootstrapStore::add_batch(int64_t query_version, util::Optionalstart_write(); - bool did_create = false; + auto bootstrap_table = tr->get_table(m_table); + auto incomplete_bootstraps = Query(bootstrap_table).not_equal(m_query_version, query_version).find_all(); + incomplete_bootstraps.for_each([&](Obj obj) { + m_logger.debug(util::LogCategory::changeset, "Clearing incomplete bootstrap for query version %1", + obj.get(m_query_version)); + return IteratorControl::AdvanceToNext; + }); + incomplete_bootstraps.clear(); - { - DisableReplication disable_replication(*tr); - auto bootstrap_table = tr->get_table(m_table); - auto incomplete_bootstraps = Query(bootstrap_table).not_equal(m_query_version, query_version).find_all(); - incomplete_bootstraps.for_each([&](Obj obj) { - m_logger.debug(util::LogCategory::changeset, "Clearing incomplete bootstrap for query version %1", - obj.get(m_query_version)); - return IteratorControl::AdvanceToNext; - }); - incomplete_bootstraps.clear(); - - auto bootstrap_obj = bootstrap_table->create_object_with_primary_key(Mixed{query_version}, &did_create); - if (progress) { - auto progress_obj = bootstrap_obj.create_and_set_linked_object(m_progress); - progress_obj.set(m_progress_latest_server_version, int64_t(progress->latest_server_version.version)); - progress_obj.set(m_progress_latest_server_version_salt, int64_t(progress->latest_server_version.salt)); - progress_obj.set(m_progress_download_server_version, int64_t(progress->download.server_version)); - progress_obj.set(m_progress_download_client_version, - int64_t(progress->download.last_integrated_client_version)); - progress_obj.set(m_progress_upload_server_version, - int64_t(progress->upload.last_integrated_server_version)); - progress_obj.set(m_progress_upload_client_version, int64_t(progress->upload.client_version)); - } + bool did_create = false; + auto bootstrap_obj = bootstrap_table->create_object_with_primary_key(Mixed{query_version}, &did_create); + if (progress) { + auto progress_obj = bootstrap_obj.create_and_set_linked_object(m_progress); + progress_obj.set(m_progress_latest_server_version, int64_t(progress->latest_server_version.version)); + progress_obj.set(m_progress_latest_server_version_salt, int64_t(progress->latest_server_version.salt)); + progress_obj.set(m_progress_download_server_version, int64_t(progress->download.server_version)); + progress_obj.set(m_progress_download_client_version, + int64_t(progress->download.last_integrated_client_version)); + progress_obj.set(m_progress_upload_server_version, int64_t(progress->upload.last_integrated_server_version)); + progress_obj.set(m_progress_upload_client_version, int64_t(progress->upload.client_version)); + } - auto changesets_list = bootstrap_obj.get_linklist(m_changesets); - for (size_t idx = 0; idx < changesets.size(); ++idx) { - auto cur_changeset = changesets_list.create_and_insert_linked_object(changesets_list.size()); - cur_changeset.set(m_changeset_remote_version, int64_t(changesets[idx].remote_version)); - cur_changeset.set(m_changeset_last_integrated_client_version, - int64_t(changesets[idx].last_integrated_local_version)); - cur_changeset.set(m_changeset_origin_file_ident, int64_t(changesets[idx].origin_file_ident)); - cur_changeset.set(m_changeset_origin_timestamp, int64_t(changesets[idx].origin_timestamp)); - cur_changeset.set(m_changeset_original_changeset_size, int64_t(changesets[idx].original_changeset_size)); - BinaryData compressed_data(compressed_changesets[idx].data(), compressed_changesets[idx].size()); - cur_changeset.set(m_changeset_data, compressed_data); - } + auto changesets_list = bootstrap_obj.get_linklist(m_changesets); + for (size_t idx = 0; idx < changesets.size(); ++idx) { + auto cur_changeset = changesets_list.create_and_insert_linked_object(changesets_list.size()); + cur_changeset.set(m_changeset_remote_version, int64_t(changesets[idx].remote_version)); + cur_changeset.set(m_changeset_last_integrated_client_version, + int64_t(changesets[idx].last_integrated_local_version)); + cur_changeset.set(m_changeset_origin_file_ident, int64_t(changesets[idx].origin_file_ident)); + cur_changeset.set(m_changeset_origin_timestamp, int64_t(changesets[idx].origin_timestamp)); + cur_changeset.set(m_changeset_original_changeset_size, int64_t(changesets[idx].original_changeset_size)); + BinaryData compressed_data(compressed_changesets[idx].data(), compressed_changesets[idx].size()); + cur_changeset.set(m_changeset_data, compressed_data); } tr->commit(); @@ -314,7 +309,6 @@ void PendingBootstrapStore::pop_front_pending(const TransactionRef& tr, size_t c if (bootstrap_table->is_empty()) { return; } - DisableReplication disable_replication(*tr); // We should only have one pending bootstrap at a time. REALM_ASSERT(bootstrap_table->size() == 1);