From f92baa3e4549d12b348d97c541a9e0153fe30d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Edelbo?= Date: Thu, 22 Feb 2024 15:14:49 +0100 Subject: [PATCH] Add ability to get path to modified collections in object notifications --- src/realm.h | 21 ++++++++++ src/realm/collection.hpp | 1 + src/realm/collection_parent.hpp | 2 + src/realm/dictionary.cpp | 22 +++++++++++ src/realm/dictionary.hpp | 1 + src/realm/list.cpp | 20 ++++++++++ src/realm/list.hpp | 1 + src/realm/obj.cpp | 10 +++++ src/realm/obj.hpp | 1 + src/realm/object-store/binding_context.hpp | 2 +- .../object-store/c_api/notifications.cpp | 38 +++++++++++++++++++ src/realm/object-store/c_api/types.hpp | 1 + .../object-store/collection_notifications.hpp | 3 +- .../impl/collection_change_builder.cpp | 2 +- src/realm/object-store/impl/list_notifier.cpp | 4 +- .../object-store/impl/object_notifier.cpp | 14 +++++-- .../object-store/impl/results_notifier.cpp | 4 +- .../impl/transact_log_handler.cpp | 27 +++++++------ src/realm/object-store/object_changeset.cpp | 14 ++++--- src/realm/object-store/object_changeset.hpp | 7 ++-- test/object-store/c_api/c_api.cpp | 25 ++++++++---- test/object-store/dictionary.cpp | 36 ++++++++++++------ test/object-store/realm.cpp | 2 +- test/object-store/transaction_log_parsing.cpp | 4 +- 24 files changed, 209 insertions(+), 53 deletions(-) diff --git a/src/realm.h b/src/realm.h index 0eb4414f7ab..9762ec00a6d 100644 --- a/src/realm.h +++ b/src/realm.h @@ -1953,6 +1953,13 @@ RLM_API bool realm_object_changes_is_deleted(const realm_object_changes_t*); */ RLM_API size_t realm_object_changes_get_num_modified_properties(const realm_object_changes_t*); +/** + * Get the number of paths to embedded collections that were modified. + * + * This function cannot fail. + */ +RLM_API size_t realm_object_changes_get_num_modified_paths(const realm_object_changes_t*); + /** * Get the column keys for the properties that were modified in an object * notification. @@ -1967,6 +1974,20 @@ RLM_API size_t realm_object_changes_get_num_modified_properties(const realm_obje RLM_API size_t realm_object_changes_get_modified_properties(const realm_object_changes_t*, realm_property_key_t* out_modified, size_t max); +/** + * Get the column keys for the properties that were modified in an object + * notification. + * + * This function cannot fail. + * + * @param out_modified Where the paths should be written. May be NULL. + * @param max The maximum number of paths to write. + * @return The number of paths written to @a out_modified, or the number + * of modified paths if @a out_modified is NULL. + */ +RLM_API size_t realm_object_changes_get_modified_paths(const realm_object_changes_t*, realm_string_t* out_modified, + size_t max); + /** * Get the number of various types of changes in a collection notification. * diff --git a/src/realm/collection.hpp b/src/realm/collection.hpp index f2b5c8f56c7..f33e17647a5 100644 --- a/src/realm/collection.hpp +++ b/src/realm/collection.hpp @@ -39,6 +39,7 @@ class DummyParent : public CollectionParent { { return {}; } + void translate_path(const StablePath&, Path&) const final {} void add_index(Path&, const Index&) const noexcept final {} size_t find_index(const Index&) const noexcept final { diff --git a/src/realm/collection_parent.hpp b/src/realm/collection_parent.hpp index d7a6f9d1e06..23c2c7ccb36 100644 --- a/src/realm/collection_parent.hpp +++ b/src/realm/collection_parent.hpp @@ -95,6 +95,8 @@ class CollectionParent : public std::enable_shared_from_this { /// Get table of owning object virtual TableRef get_table() const noexcept = 0; + virtual void translate_path(const StablePath&, Path&) const = 0; + protected: friend class Collection; template diff --git a/src/realm/dictionary.cpp b/src/realm/dictionary.cpp index 854d51cfc6f..e8c8ae29324 100644 --- a/src/realm/dictionary.cpp +++ b/src/realm/dictionary.cpp @@ -638,6 +638,28 @@ Dictionary::Iterator Dictionary::find(Mixed key) const noexcept return end(); } + +void Dictionary::translate_path(const StablePath& stable_path, Path& path) const +{ + auto& index = stable_path[m_level]; + auto ndx = find_index(index); + StringData key = do_get_key(ndx).get_string(); + path.emplace_back(key); + if (stable_path.size() > m_level + 1) { + Mixed val = do_get(ndx); + if (val.is_type(type_Dictionary)) { + DummyParent parent(this->get_table(), val.get_ref()); + Dictionary dict(parent, 0); + dict.translate_path(stable_path, path); + } + else if (val.is_type(type_List)) { + DummyParent parent(this->get_table(), val.get_ref()); + Lst list(parent, 0); + list.translate_path(stable_path, path); + } + } +} + void Dictionary::add_index(Path& path, const Index& index) const { auto ndx = m_values->find_key(index.get_salt()); diff --git a/src/realm/dictionary.hpp b/src/realm/dictionary.hpp index 3cf08e9b91c..a9dec07f21f 100644 --- a/src/realm/dictionary.hpp +++ b/src/realm/dictionary.hpp @@ -205,6 +205,7 @@ class Dictionary final : public CollectionBaseImpl, public Colle { return Base::get_stable_path(); } + void translate_path(const StablePath& stable_path, Path& path) const final; void add_index(Path& path, const Index& ndx) const final; size_t find_index(const Index&) const final; diff --git a/src/realm/list.cpp b/src/realm/list.cpp index 2bd3ffff183..18b0843ad81 100644 --- a/src/realm/list.cpp +++ b/src/realm/list.cpp @@ -790,6 +790,26 @@ void Lst::set_collection_ref(Index index, ref_type ref, CollectionType ty m_tree->set(ndx, Mixed(ref, type)); } +void Lst::translate_path(const StablePath& stable_path, Path& path) const +{ + auto& index = stable_path[m_level]; + auto ndx = find_index(index); + path.emplace_back(ndx); + if (stable_path.size() > m_level + 1) { + Mixed val = get(ndx); + if (val.is_type(type_Dictionary)) { + DummyParent parent(this->get_table(), val.get_ref()); + Dictionary dict(parent, 0); + dict.translate_path(stable_path, path); + } + else if (val.is_type(type_List)) { + DummyParent parent(this->get_table(), val.get_ref()); + Lst list(parent, 0); + list.translate_path(stable_path, path); + } + } +} + void Lst::add_index(Path& path, const Index& index) const { auto ndx = m_tree->find_key(index.get_salt()); diff --git a/src/realm/list.hpp b/src/realm/list.hpp index d3bca568116..8e87d62e0d9 100644 --- a/src/realm/list.hpp +++ b/src/realm/list.hpp @@ -484,6 +484,7 @@ class Lst final : public CollectionBaseImpl, public CollectionPa { return Base::get_stable_path(); } + void translate_path(const StablePath& stable_path, Path& path) const final; ColKey get_col_key() const noexcept override { diff --git a/src/realm/obj.cpp b/src/realm/obj.cpp index aaa08a411cf..5b9549fafa8 100644 --- a/src/realm/obj.cpp +++ b/src/realm/obj.cpp @@ -2079,6 +2079,16 @@ CollectionPtr Obj::get_collection_ptr(const Path& path) const return collection; } +void Obj::translate_path(const StablePath& stable_path, Path& path) const +{ + ColKey col_key = m_table->get_column_key(stable_path[0]); + path.emplace_back(m_table->get_column_name(col_key)); + if (stable_path.size() > 1) { + CollectionBasePtr collection = get_collection_ptr(col_key); + dynamic_cast(collection.get())->translate_path(stable_path, path); + } +} + CollectionPtr Obj::get_collection_by_stable_path(const StablePath& path) const { // First element in path is phony column key diff --git a/src/realm/obj.hpp b/src/realm/obj.hpp index edf9db3aa60..d3a5cc4b4fa 100644 --- a/src/realm/obj.hpp +++ b/src/realm/obj.hpp @@ -78,6 +78,7 @@ class Obj : public CollectionParent { Path get_short_path() const noexcept final; ColKey get_col_key() const noexcept final; StablePath get_stable_path() const noexcept final; + void translate_path(const StablePath&, Path&) const final; void add_index(Path& path, const Index& ndx) const final; size_t find_index(const Index&) const final { diff --git a/src/realm/object-store/binding_context.hpp b/src/realm/object-store/binding_context.hpp index 26a7cb62894..5a6e8c42c1e 100644 --- a/src/realm/object-store/binding_context.hpp +++ b/src/realm/object-store/binding_context.hpp @@ -165,7 +165,7 @@ class BindingContext { // Populated with information about which columns were changed // May be shorter than the actual number of columns if the later columns // are not modified - std::unordered_map changes; + std::unordered_map changes; // Simple lexographic ordering friend bool operator<(ObserverState const& lft, ObserverState const& rgt) diff --git a/src/realm/object-store/c_api/notifications.cpp b/src/realm/object-store/c_api/notifications.cpp index 666e3110fcf..3de35080ed7 100644 --- a/src/realm/object-store/c_api/notifications.cpp +++ b/src/realm/object-store/c_api/notifications.cpp @@ -113,6 +113,11 @@ RLM_API size_t realm_object_changes_get_num_modified_properties(const realm_obje return changes->columns.size(); } +RLM_API size_t realm_object_changes_get_num_modified_paths(const realm_object_changes_t* changes) +{ + return changes->modified_paths.size(); +} + RLM_API size_t realm_object_changes_get_modified_properties(const realm_object_changes_t* changes, realm_property_key_t* out_properties, size_t max) { @@ -130,6 +135,39 @@ RLM_API size_t realm_object_changes_get_modified_properties(const realm_object_c return i; } +RLM_API size_t realm_object_changes_get_modified_paths(const realm_object_changes_t* const_changes, + realm_string_t* out_paths, size_t max) +{ + if (!out_paths) + return const_changes->modified_paths.size(); + + realm_object_changes_t* changes = const_cast(const_changes); + changes->path_buffer.resize(changes->modified_paths.size()); + size_t i = 0; + for (const auto& p : changes->modified_paths) { + if (i >= max) { + break; + } + std::string& path = changes->path_buffer[i]; + path = p[0].get_key(); + for (auto path_elem = p.begin() + 1; path_elem != p.end(); ++path_elem) { + if (path_elem->is_key()) { + path += '.'; + path += path_elem->get_key(); + } + else { + char buffer[10]; + sprintf(buffer, "[%u]", unsigned(path_elem->get_ndx())); + path += buffer; + } + } + out_paths[i].data = path.data(); + out_paths[i].size = path.size(); + ++i; + } + return i; +} + RLM_API realm_notification_token_t* realm_list_add_notification_callback(realm_list_t* list, realm_userdata_t userdata, realm_free_userdata_func_t free, diff --git a/src/realm/object-store/c_api/types.hpp b/src/realm/object-store/c_api/types.hpp index 317fc09fec9..4c46cc60dd7 100644 --- a/src/realm/object-store/c_api/types.hpp +++ b/src/realm/object-store/c_api/types.hpp @@ -428,6 +428,7 @@ struct realm_object_changes : realm::c_api::WrapC, realm::CollectionChangeSet { { return new realm_object_changes{static_cast(*this)}; } + std::vector path_buffer; }; struct realm_collection_changes : realm::c_api::WrapC, realm::CollectionChangeSet { diff --git a/src/realm/object-store/collection_notifications.hpp b/src/realm/object-store/collection_notifications.hpp index 88648271e52..ce953e462e0 100644 --- a/src/realm/object-store/collection_notifications.hpp +++ b/src/realm/object-store/collection_notifications.hpp @@ -105,8 +105,9 @@ struct CollectionChangeSet { // Per-column version of `modifications` std::unordered_map columns; + std::vector modified_paths; - std::set paths; + std::set stable_paths; bool empty() const noexcept { diff --git a/src/realm/object-store/impl/collection_change_builder.cpp b/src/realm/object-store/impl/collection_change_builder.cpp index 66f9923bcae..5bbdb546b36 100644 --- a/src/realm/object-store/impl/collection_change_builder.cpp +++ b/src/realm/object-store/impl/collection_change_builder.cpp @@ -704,5 +704,5 @@ CollectionChangeSet CollectionChangeBuilder::finalize() && return {std::move(deletions), std::move(insertions), std::move(modifications_in_old), std::move(modifications), std::move(moves), collection_root_was_deleted, - collection_was_cleared, std::move(columns)}; + collection_was_cleared, std::move(columns), std::move(modified_paths)}; } diff --git a/src/realm/object-store/impl/list_notifier.cpp b/src/realm/object-store/impl/list_notifier.cpp index 0de163fa7fa..cbe1908112b 100644 --- a/src/realm/object-store/impl/list_notifier.cpp +++ b/src/realm/object-store/impl/list_notifier.cpp @@ -142,9 +142,9 @@ void ListNotifier::run() } } - if (m_change.paths.size()) { + if (m_change.stable_paths.size()) { if (auto coll = dynamic_cast(m_list.get())) { - for (auto& p : m_change.paths) { + for (auto& p : m_change.stable_paths) { // Report changes in substructure as modifications on this list auto ndx = coll->find_index(p[0]); if (ndx != realm::not_found) diff --git a/src/realm/object-store/impl/object_notifier.cpp b/src/realm/object-store/impl/object_notifier.cpp index 86feba916d0..e82bf192ffc 100644 --- a/src/realm/object-store/impl/object_notifier.cpp +++ b/src/realm/object-store/impl/object_notifier.cpp @@ -109,13 +109,19 @@ void ObjectNotifier::run() const auto& change = it->second; - auto column_modifications = change.get_columns_modified(m_obj_key); - if (!column_modifications) + auto path_modifications = change.get_paths_modified(m_obj_key); + if (!path_modifications) return; // Finally we add all changes to `m_change` which is later used to notify about the changed columns. m_change.modifications.add(0); - for (auto col : *column_modifications) { - m_change.columns[col.value].add(0); + auto obj = m_table->get_object(m_obj_key); + for (const StablePath& stable_path : *path_modifications) { + m_change.columns[m_table->get_column_key(stable_path[0]).value].add(0); + if (stable_path.size() > 1) { + Path path; + obj.translate_path(stable_path, path); + m_change.modified_paths.emplace_back(std::move(path)); + } } } diff --git a/src/realm/object-store/impl/results_notifier.cpp b/src/realm/object-store/impl/results_notifier.cpp index 92ad8292f57..3455e468dbd 100644 --- a/src/realm/object-store/impl/results_notifier.cpp +++ b/src/realm/object-store/impl/results_notifier.cpp @@ -393,9 +393,9 @@ void ListResultsNotifier::run() std::iota(m_run_indices->begin(), m_run_indices->end(), 0); } - if (m_change.paths.size()) { + if (m_change.stable_paths.size()) { if (auto coll = dynamic_cast(m_list.get())) { - for (auto& p : m_change.paths) { + for (auto& p : m_change.stable_paths) { // Report changes in substructure as modifications on this list auto ndx = coll->find_index(p[0]); if (ndx != realm::not_found) diff --git a/src/realm/object-store/impl/transact_log_handler.cpp b/src/realm/object-store/impl/transact_log_handler.cpp index ed56dc11595..b723ed46699 100644 --- a/src/realm/object-store/impl/transact_log_handler.cpp +++ b/src/realm/object-store/impl/transact_log_handler.cpp @@ -110,10 +110,10 @@ void KVOAdapter::before(Transaction& sg) m_invalidated.push_back(observer.info); continue; } - auto column_modifications = table.get_columns_modified(key); - if (column_modifications) { - for (auto col : *column_modifications) { - observer.changes[col.value].kind = BindingContext::ColumnInfo::Kind::Set; + auto tbl = sg.get_table(observer.table_key); + if (auto path_modifications = table.get_paths_modified(key)) { + for (const StablePath& path : *path_modifications) { + observer.changes[tbl->get_column_key(path[0])].kind = BindingContext::ColumnInfo::Kind::Set; } } } @@ -123,7 +123,7 @@ void KVOAdapter::before(Transaction& sg) // We may have pre-emptively marked the column as modified if the // LinkList was selected but the actual changes made ended up being // a no-op - list.observer->changes.erase(list.col_key.value); + list.observer->changes.erase(list.col_key); continue; } // If the containing row was deleted then changes will be empty @@ -132,7 +132,7 @@ void KVOAdapter::before(Transaction& sg) continue; } // otherwise the column should have been marked as modified - auto it = list.observer->changes.find(list.col_key.value); + auto it = list.observer->changes.find(list.col_key); REALM_ASSERT(it != list.observer->changes.end()); auto& builder = list.builder; auto& changes = it->second; @@ -364,9 +364,11 @@ class TransactLogObserver : public TransactLogValidationMixin { return true; } - bool select_collection(ColKey col, ObjKey obj, const StablePath& path) + bool select_collection(ColKey, ObjKey obj, const StablePath& path) { - modify_object(col, obj); + if (m_active_table) { + m_active_table->modifications_add(obj, path); + } auto table = current_table(); for (auto& c : m_info.collections) { @@ -374,7 +376,7 @@ class TransactLogObserver : public TransactLogValidationMixin { if (c.path.size() != path.size()) { StablePath sub_path; sub_path.insert(sub_path.begin(), path.begin() + c.path.size(), path.end()); - c.changes->paths.insert(std::move(sub_path)); + c.changes->stable_paths.insert(std::move(sub_path)); } else { m_active_collection = c.changes; @@ -465,8 +467,11 @@ class TransactLogObserver : public TransactLogValidationMixin { bool modify_object(ColKey col, ObjKey key) { - if (m_active_table) - m_active_table->modifications_add(key, col); + if (m_active_table) { + StablePath path; + path.push_back(StableIndex(col, 0)); + m_active_table->modifications_add(key, path); + } return true; } diff --git a/src/realm/object-store/object_changeset.cpp b/src/realm/object-store/object_changeset.cpp index 922a6a8ad28..6798240123d 100644 --- a/src/realm/object-store/object_changeset.cpp +++ b/src/realm/object-store/object_changeset.cpp @@ -25,11 +25,11 @@ void ObjectChangeSet::insertions_add(ObjKey obj) m_insertions.insert(obj); } -void ObjectChangeSet::modifications_add(ObjKey obj, ColKey col) +void ObjectChangeSet::modifications_add(ObjKey obj, const StablePath& path) { // don't report modifications on new objects if (m_insertions.find(obj) == m_insertions.end()) { - m_modifications[obj].insert(col); + m_modifications[obj].insert(path); } } @@ -82,9 +82,13 @@ bool ObjectChangeSet::modifications_contains(ObjKey obj, const std::vector& changed_columns_for_object = m_modifications.at(obj); + const std::set& changed_paths_for_object = m_modifications.at(obj); for (const auto& column_key_in_filter : filtered_column_keys) { - if (changed_columns_for_object.count(column_key_in_filter)) { + auto it = + std::find_if(changed_paths_for_object.begin(), changed_paths_for_object.end(), [&](const StablePath& p) { + return p[0].get_index().val == column_key_in_filter.get_index().val; + }); + if (it != changed_paths_for_object.end()) { return true; } } @@ -92,7 +96,7 @@ bool ObjectChangeSet::modifications_contains(ObjKey obj, const std::vector; using ColumnSet = std::unordered_set; - using ObjectMapToColumnSet = std::unordered_map; + using PathSet = std::set; + using ObjectMapToColumnSet = std::unordered_map; ObjectChangeSet() = default; ObjectChangeSet(ObjectChangeSet const&) = default; @@ -47,7 +48,7 @@ class ObjectChangeSet { ObjectChangeSet& operator=(ObjectChangeSet&&) = default; void insertions_add(ObjKey obj); - void modifications_add(ObjKey obj, ColKey col); + void modifications_add(ObjKey obj, const StablePath& path); void deletions_add(ObjKey obj); bool insertions_remove(ObjKey obj); @@ -69,7 +70,7 @@ class ObjectChangeSet { bool deletions_contains(ObjKey obj) const; // if the specified object has not been modified, returns nullptr // if the object has been modified, returns a pointer to the ObjectSet - const ColumnSet* get_columns_modified(ObjKey obj) const; + const PathSet* get_paths_modified(ObjKey obj) const; bool insertions_empty() const noexcept { diff --git a/test/object-store/c_api/c_api.cpp b/test/object-store/c_api/c_api.cpp index 8ff23ceef80..0e4aaa38b2c 100644 --- a/test/object-store/c_api/c_api.cpp +++ b/test/object-store/c_api/c_api.cpp @@ -4066,8 +4066,8 @@ TEST_CASE("C API - properties", "[c_api]") { realm_property_key_t modified_keys[2]; size_t n = realm_object_changes_get_modified_properties(state.changes.get(), modified_keys, 2); CHECK(n == 2); - CHECK(modified_keys[0] == foo_int_key); - CHECK(modified_keys[1] == foo_str_key); + CHECK(modified_keys[0] == foo_str_key); + CHECK(modified_keys[1] == foo_int_key); n = realm_object_changes_get_modified_properties(state.changes.get(), nullptr, 2); CHECK(n == 2); @@ -5257,6 +5257,7 @@ TEST_CASE("C API: nested collections", "[c_api]") { size_t modifications; bool was_deleted; realm_dictionary_t* dict; + std::vector paths; } user_data; auto parent_dict = cptr_checked(realm_set_dictionary(obj1.get(), foo_any_col_key)); @@ -5286,20 +5287,28 @@ TEST_CASE("C API: nested collections", "[c_api]") { CHECK(!realm_dictionary_is_valid(user_data->dict)); } }; - auto require_change = [&]() { - auto token = cptr_checked(realm_dictionary_add_notification_callback(dict2.get(), &user_data, nullptr, - nullptr, on_dictionary_change)); - checked(realm_refresh(realm, nullptr)); - return token; + auto on_obj_change = [](void* userdata, const realm_object_changes_t* changes) { + auto state = static_cast(userdata); + realm_string_t paths[10]; + auto num = realm_object_changes_get_modified_paths(changes, paths, 10); + for (size_t i = 0; i < num; i++) { + state->paths.emplace_back(paths[0].data, paths[0].size); + } }; - auto token = require_change(); + auto token_dict = cptr_checked(realm_dictionary_add_notification_callback(dict2.get(), &user_data, nullptr, + nullptr, on_dictionary_change)); + auto token = + cptr(realm_object_add_notification_callback(obj1.get(), &user_data, nullptr, nullptr, on_obj_change)); + checked(realm_refresh(realm, nullptr)); write([&] { checked(realm_dictionary_insert(dict2.get(), rlm_str_val("Nested-Godbye"), rlm_str_val("Nested-CruelWorld"), nullptr, nullptr)); }); CHECK(user_data.insertions == 1); + REQUIRE(user_data.paths.size() == 1); + CHECK(user_data.paths[0] == "any.Hi"); write([&] { realm_dictionary_insert(dict.get(), rlm_str_val("Hi"), rlm_str_val("Foo"), nullptr, nullptr); diff --git a/test/object-store/dictionary.cpp b/test/object-store/dictionary.cpp index 955a1ad6ff1..eb021e71c45 100644 --- a/test/object-store/dictionary.cpp +++ b/test/object-store/dictionary.cpp @@ -83,6 +83,13 @@ TEST_CASE("nested dictionary in mixed", "[dictionary]") { change_dictionary = c; }); + Object object(r, any_obj); + CollectionChangeSet change_obj; + auto token_obj = object.add_notification_callback([&](CollectionChangeSet c) { + change_obj = c; + }); + + auto write = [&](auto&& f) { r->begin_transaction(); f(); @@ -100,11 +107,11 @@ TEST_CASE("nested dictionary in mixed", "[dictionary]") { auto list = dict_mixed.get_list("list"); SECTION("notification on nested list") { - CollectionChangeSet change; + CollectionChangeSet change_list; auto require_change = [&] { auto token = list.add_notification_callback([&](CollectionChangeSet c) { - change = c; + change_list = c; }); advance_and_notify(*r); return token; @@ -116,7 +123,12 @@ TEST_CASE("nested dictionary in mixed", "[dictionary]") { list.add(Mixed{5}); list.add(Mixed{6}); }); - REQUIRE_INDICES(change.insertions, 0, 1); + Path modified_path; + modified_path.emplace_back("any"); + modified_path.emplace_back("list"); + REQUIRE(change_obj.modified_paths.size() == 1); + CHECK(change_obj.modified_paths[0] == modified_path); + REQUIRE_INDICES(change_list.insertions, 0, 1); REQUIRE_INDICES(change_dictionary.modifications, 1); } @@ -143,13 +155,13 @@ TEST_CASE("nested dictionary in mixed", "[dictionary]") { list.add(Mixed{5}); list.add(Mixed{6}); }); - REQUIRE_INDICES(change.insertions, 0, 1); + REQUIRE_INDICES(change_list.insertions, 0, 1); write([&] { dict_mixed.insert("list", 42); }); - REQUIRE_INDICES(change.deletions, 0, 1); + REQUIRE_INDICES(change_list.deletions, 0, 1); REQUIRE_INDICES(change_dictionary.modifications, 1); - REQUIRE(change.collection_root_was_deleted); + REQUIRE(change_list.collection_root_was_deleted); } SECTION("erase containing dictionary") { auto token = require_change(); @@ -157,12 +169,12 @@ TEST_CASE("nested dictionary in mixed", "[dictionary]") { list.add(Mixed{5}); list.add(Mixed{6}); }); - REQUIRE_INDICES(change.insertions, 0, 1); + REQUIRE_INDICES(change_list.insertions, 0, 1); write([&] { any_obj.set(col_any, Mixed(42)); }); - REQUIRE_INDICES(change.deletions, 0, 1); - REQUIRE(change.collection_root_was_deleted); + REQUIRE_INDICES(change_list.deletions, 0, 1); + REQUIRE(change_list.collection_root_was_deleted); } SECTION("erase containing object") { auto token = require_change(); @@ -170,12 +182,12 @@ TEST_CASE("nested dictionary in mixed", "[dictionary]") { list.add(Mixed{5}); list.add(Mixed{6}); }); - REQUIRE_INDICES(change.insertions, 0, 1); + REQUIRE_INDICES(change_list.insertions, 0, 1); write([&] { any_obj.remove(); }); - REQUIRE_INDICES(change.deletions, 0, 1); - REQUIRE(change.collection_root_was_deleted); + REQUIRE_INDICES(change_list.deletions, 0, 1); + REQUIRE(change_list.collection_root_was_deleted); } } SECTION("dictionary as Results") { diff --git a/test/object-store/realm.cpp b/test/object-store/realm.cpp index 9171a72be8a..bd4a4d0bfb0 100644 --- a/test/object-store/realm.cpp +++ b/test/object-store/realm.cpp @@ -96,7 +96,7 @@ class Observer : public BindingContext { IndexSet array_change(size_t index, ColKey col_key) const noexcept { auto& changes = m_result[index].changes; - auto col = changes.find(col_key.value); + auto col = changes.find(col_key); return col == changes.end() ? IndexSet{} : col->second.indices; } diff --git a/test/object-store/transaction_log_parsing.cpp b/test/object-store/transaction_log_parsing.cpp index 3de2cfc6e1a..a1a76198edc 100644 --- a/test/object-store/transaction_log_parsing.cpp +++ b/test/object-store/transaction_log_parsing.cpp @@ -194,7 +194,7 @@ class KVOContext : public BindingContext { }); if (it == m_result.end()) return false; - auto col = it->changes.find(col_key.value); + auto col = it->changes.find(col_key); return col != it->changes.end() && col->second.kind != BindingContext::ColumnInfo::Kind::None; } @@ -206,7 +206,7 @@ class KVOContext : public BindingContext { ArrayChange array_change(size_t index, ColKey col_key) const noexcept { auto& changes = m_result[index].changes; - auto col = changes.find(col_key.value); + auto col = changes.find(col_key); return col == changes.end() ? ArrayChange{ColumnInfo::Kind::None, {}} : ArrayChange{col->second.kind, col->second.indices}; }