-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve FLX/Subscriptions API to be more friendly to direct binding #6065
Changes from 2 commits
06e824a
c1faa6d
9838837
1d7aa7e
e6f4a29
78bca0b
59ecc8e
f5379ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -507,41 +507,41 @@ RLM_API void realm_sync_config_set_resync_mode(realm_sync_config_t* config, | |
RLM_API realm_object_id_t realm_sync_subscription_id(const realm_flx_sync_subscription_t* subscription) noexcept | ||
{ | ||
REALM_ASSERT(subscription != nullptr); | ||
return to_capi(subscription->id()); | ||
return to_capi(subscription->id); | ||
} | ||
|
||
RLM_API realm_string_t realm_sync_subscription_name(const realm_flx_sync_subscription_t* subscription) noexcept | ||
{ | ||
REALM_ASSERT(subscription != nullptr); | ||
return to_capi(subscription->name()); | ||
return to_capi(subscription->name ? "" : *subscription->name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This preserves the old behavior of never returning a "null" string. But perhaps it is the old behavior that is wrong and I should just return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I gave up on preserving this behavior. I think it was wrong anyway. The only way to get it is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I recall this correctly, the problem was to determine whether the string was null because of some error or just because the subscription name was not set, probably, returning a simple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new code is just I don't see how the old code provided a way to distinguish errors from unset strings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current version of this line is here fwiw https://github.com/realm/realm-core/pull/6065/files#diff-ba7e9e5a00e04033638ced899e7f7f613243e4e2685fbdf3c519798b4e711d35R516 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I think it is fine like it is... I would not check the pointer in there, the most important thing is that we don't end up hitting another ctor by mistake in the future and crash because of a subscription that does not have a name :-) |
||
} | ||
|
||
RLM_API realm_string_t | ||
realm_sync_subscription_object_class_name(const realm_flx_sync_subscription_t* subscription) noexcept | ||
{ | ||
REALM_ASSERT(subscription != nullptr); | ||
return to_capi(subscription->object_class_name()); | ||
return to_capi(subscription->object_class_name); | ||
} | ||
|
||
RLM_API realm_string_t | ||
realm_sync_subscription_query_string(const realm_flx_sync_subscription_t* subscription) noexcept | ||
{ | ||
REALM_ASSERT(subscription != nullptr); | ||
return to_capi(subscription->query_string()); | ||
return to_capi(subscription->query_string); | ||
} | ||
|
||
RLM_API realm_timestamp_t | ||
realm_sync_subscription_created_at(const realm_flx_sync_subscription_t* subscription) noexcept | ||
{ | ||
REALM_ASSERT(subscription != nullptr); | ||
return to_capi(subscription->created_at()); | ||
return to_capi(subscription->created_at); | ||
} | ||
|
||
RLM_API realm_timestamp_t | ||
realm_sync_subscription_updated_at(const realm_flx_sync_subscription_t* subscription) noexcept | ||
{ | ||
REALM_ASSERT(subscription != nullptr); | ||
return to_capi(subscription->updated_at()); | ||
return to_capi(subscription->updated_at); | ||
} | ||
|
||
RLM_API void realm_sync_config_set_before_client_reset_handler(realm_sync_config_t* config, | ||
|
@@ -654,10 +654,10 @@ realm_sync_find_subscription_by_name(const realm_flx_sync_subscription_set_t* su | |
const char* name) noexcept | ||
{ | ||
REALM_ASSERT(subscription_set != nullptr); | ||
auto it = subscription_set->find(name); | ||
if (it == subscription_set->end()) | ||
auto ptr = subscription_set->find(name); | ||
if (!ptr) | ||
return nullptr; | ||
return new realm_flx_sync_subscription_t(*it); | ||
return new realm_flx_sync_subscription_t(*ptr); | ||
} | ||
|
||
RLM_API realm_flx_sync_subscription_t* | ||
|
@@ -666,10 +666,10 @@ realm_sync_find_subscription_by_results(const realm_flx_sync_subscription_set_t* | |
{ | ||
REALM_ASSERT(subscription_set != nullptr); | ||
auto realm_query = add_ordering_to_realm_query(results->get_query(), results->get_ordering()); | ||
auto it = subscription_set->find(realm_query); | ||
if (it == subscription_set->end()) | ||
auto ptr = subscription_set->find(realm_query); | ||
if (!ptr) | ||
return nullptr; | ||
return new realm_flx_sync_subscription_t{*it}; | ||
return new realm_flx_sync_subscription_t{*ptr}; | ||
} | ||
|
||
RLM_API realm_flx_sync_subscription_t* | ||
|
@@ -690,10 +690,10 @@ realm_sync_find_subscription_by_query(const realm_flx_sync_subscription_set_t* s | |
{ | ||
REALM_ASSERT(subscription_set != nullptr); | ||
auto realm_query = add_ordering_to_realm_query(query->get_query(), query->get_ordering()); | ||
auto it = subscription_set->find(realm_query); | ||
if (it == subscription_set->end()) | ||
auto ptr = subscription_set->find(realm_query); | ||
if (!ptr) | ||
return nullptr; | ||
return new realm_flx_sync_subscription_t(*it); | ||
return new realm_flx_sync_subscription_t(*ptr); | ||
} | ||
|
||
RLM_API bool realm_sync_subscription_set_refresh(realm_flx_sync_subscription_set_t* subscription_set) | ||
|
@@ -762,7 +762,7 @@ RLM_API bool realm_sync_subscription_set_erase_by_id(realm_flx_sync_mutable_subs | |
*erased = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure if I should delete these. They ensure that |
||
return wrap_err([&] { | ||
auto it = std::find_if(subscription_set->begin(), subscription_set->end(), [id](const Subscription& sub) { | ||
return from_capi(*id) == sub.id(); | ||
return from_capi(*id) == sub.id; | ||
}); | ||
if (it != subscription_set->end()) { | ||
subscription_set->erase(it); | ||
|
@@ -778,10 +778,7 @@ RLM_API bool realm_sync_subscription_set_erase_by_name(realm_flx_sync_mutable_su | |
REALM_ASSERT(subscription_set != nullptr && name != nullptr); | ||
*erased = false; | ||
return wrap_err([&]() { | ||
if (auto it = subscription_set->find(name); it != subscription_set->end()) { | ||
subscription_set->erase(it); | ||
*erased = true; | ||
} | ||
*erased = subscription_set->erase(name); | ||
return true; | ||
}); | ||
} | ||
|
@@ -793,10 +790,7 @@ RLM_API bool realm_sync_subscription_set_erase_by_query(realm_flx_sync_mutable_s | |
*erased = false; | ||
return wrap_err([&]() { | ||
auto realm_query = add_ordering_to_realm_query(query->get_query(), query->get_ordering()); | ||
if (auto it = subscription_set->find(realm_query); it != subscription_set->end()) { | ||
subscription_set->erase(it); | ||
*erased = true; | ||
} | ||
*erased = subscription_set->erase(realm_query); | ||
return true; | ||
}); | ||
} | ||
|
@@ -808,10 +802,7 @@ RLM_API bool realm_sync_subscription_set_erase_by_results(realm_flx_sync_mutable | |
*erased = false; | ||
return wrap_err([&]() { | ||
auto realm_query = add_ordering_to_realm_query(results->get_query(), results->get_ordering()); | ||
if (auto it = subscription_set->find(realm_query); it != subscription_set->end()) { | ||
subscription_set->erase(it); | ||
*erased = true; | ||
} | ||
*erased = subscription_set->erase(realm_query); | ||
return true; | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This drive-by fix removes an unused header warning for
timestamp.hpp
insubscriptions.hpp
which clearly usesTimestamp