Skip to content

Commit

Permalink
code review + some fixes in the client reset logic for handling mixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicola-cab committed Jul 19, 2023
1 parent 12b91a2 commit 2dd35e8
Show file tree
Hide file tree
Showing 3 changed files with 511 additions and 92 deletions.
19 changes: 2 additions & 17 deletions src/realm/object_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*
**************************************************************************/
#include <iostream>

#include <realm/object_converter.hpp>

Expand Down Expand Up @@ -349,14 +348,7 @@ void InterRealmValueConverter::handle_list_in_mixed(const Lst<Mixed>& src_list,
handle_dict_copy(i);
}
else {
// copy single element
InterRealmValueConverter::ConversionResult converted_src;
auto dst_obj = dst_list.get_obj();
auto dst_col = dst_list.get_col_key();
auto dst_mixed = dst_obj.get_any(dst_col);
if (cmp_src_to_dst(any, dst_mixed, &converted_src, update_out)) {
dst_list.insert(i, converted_src.converted_value);
}
dst_list.insert(i, any);
}
}
}
Expand Down Expand Up @@ -410,14 +402,7 @@ void InterRealmValueConverter::handle_dictionary_in_mixed(const Dictionary& src_
handle_dict_copy(key.get_string());
}
else {
// copy single element
InterRealmValueConverter::ConversionResult converted_src;
auto dst_obj = dst_dict.get_obj();
auto dst_col = dst_dict.get_col_key();
auto dst_mixed = dst_obj.get_any(dst_col);
if (cmp_src_to_dst(any, dst_mixed, &converted_src, update_out)) {
dst_dict.insert(key, converted_src.converted_value);
}
dst_dict.insert(key, any);
}
}
}
Expand Down
41 changes: 40 additions & 1 deletion src/realm/sync/noinst/client_reset_recovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,46 @@ bool RecoverLocalChangesetsHandler::resolve_path(ListPath& path, Obj remote_obj,
return false;
}
}
else { // single link to embedded object
else if (col.get_type() == col_type_Mixed) {
StringData col_name = remote_obj.get_table()->get_column_name(col);
auto local_any = local_obj.get_any(col_name);
auto remote_any = remote_obj.get_any(col);

if (local_any.is_type(type_List) && remote_any.is_type(type_List)) {
++it;
if (it == path.end()) {
auto local_col = local_obj.get_table()->get_column_key(col_name);
Lst<Mixed> local_list{local_obj, local_col};
Lst<Mixed> remote_list{remote_obj, col};
callback(remote_list, local_list);
return true;
}
else {
// same as above.
REALM_UNREACHABLE();
}
}
else if (local_any.is_type(type_Dictionary) && remote_any.is_type(type_Dictionary)) {
++it;
REALM_ASSERT(it != path.end());
REALM_ASSERT(it->type == ListPath::Element::Type::InternKey);
StringData col_name = remote_obj.get_table()->get_column_name(col);
auto local_col = local_obj.get_table()->get_column_key(col_name);
Dictionary remote_dict{remote_obj, col};
Dictionary local_dict{local_obj, local_col};
StringData dict_key = m_intern_keys.get_key(it->intern_key);
if (remote_dict.contains(dict_key) && local_dict.contains(dict_key)) {
remote_obj = remote_dict.get_object(dict_key);
local_obj = local_dict.get_object(dict_key);
++it;
}
else {
return false;
}
}
}
else {
// single link to embedded object
// Neither embedded object sets nor Mixed(TypedLink) to embedded objects are supported.
REALM_ASSERT_EX(!col.is_collection(), col);
REALM_ASSERT_EX(col.get_type() == col_type_Link, col);
Expand Down
Loading

0 comments on commit 2dd35e8

Please sign in to comment.