mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 23:04:29 +00:00
Always deliver results to the correct SharedGroup
If there are multiple Realm instances for a single file on a single thread due to disabling caching we need to actually deliver the results to the appropriate SharedGroup for each notifier rather than delivering them all to the first one.
This commit is contained in:
parent
8879212111
commit
632d757014
@ -180,10 +180,13 @@ void CollectionNotifier::prepare_handover()
|
||||
do_prepare_handover(*m_sg);
|
||||
}
|
||||
|
||||
bool CollectionNotifier::deliver(SharedGroup& sg, std::exception_ptr err)
|
||||
bool CollectionNotifier::deliver(Realm& realm, SharedGroup& sg, std::exception_ptr err)
|
||||
{
|
||||
if (!is_for_current_thread()) {
|
||||
return false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_realm_mutex);
|
||||
if (m_realm.get() != &realm) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (err) {
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace realm {
|
||||
@ -109,7 +108,7 @@ public:
|
||||
|
||||
virtual void run() = 0;
|
||||
void prepare_handover();
|
||||
bool deliver(SharedGroup&, std::exception_ptr);
|
||||
bool deliver(Realm&, SharedGroup&, std::exception_ptr);
|
||||
|
||||
protected:
|
||||
bool have_callbacks() const noexcept { return m_have_callbacks; }
|
||||
@ -124,9 +123,6 @@ private:
|
||||
virtual bool do_deliver(SharedGroup&) { return true; }
|
||||
virtual bool do_add_required_change_info(TransactionChangeInfo&) = 0;
|
||||
|
||||
const std::thread::id m_thread_id = std::this_thread::get_id();
|
||||
bool is_for_current_thread() const { return m_thread_id == std::this_thread::get_id(); }
|
||||
|
||||
mutable std::mutex m_realm_mutex;
|
||||
std::shared_ptr<Realm> m_realm;
|
||||
|
||||
|
@ -567,7 +567,7 @@ void RealmCoordinator::advance_to_ready(Realm& realm)
|
||||
|
||||
// Query version now matches the SG version, so we can deliver them
|
||||
for (auto& notifier : m_notifiers) {
|
||||
if (notifier->deliver(sg, m_async_error)) {
|
||||
if (notifier->deliver(realm, sg, m_async_error)) {
|
||||
notifiers.push_back(notifier);
|
||||
}
|
||||
}
|
||||
@ -586,7 +586,7 @@ void RealmCoordinator::process_available_async(Realm& realm)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_notifier_mutex);
|
||||
for (auto& notifier : m_notifiers) {
|
||||
if (notifier->deliver(sg, m_async_error)) {
|
||||
if (notifier->deliver(realm, sg, m_async_error)) {
|
||||
notifiers.push_back(notifier);
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,8 @@ TEST_CASE("list") {
|
||||
// Each of the Lists now has a different source version and state at
|
||||
// that version, so they should all see different changes despite
|
||||
// being for the same LinkList
|
||||
advance_and_notify(*r);
|
||||
for (auto& list : lists)
|
||||
advance_and_notify(*list.get_realm());
|
||||
|
||||
REQUIRE_INDICES(changes[0].insertions, 0, 1, 2);
|
||||
REQUIRE(changes[0].modifications.empty());
|
||||
@ -224,7 +225,8 @@ TEST_CASE("list") {
|
||||
|
||||
// After making another change, they should all get the same notification
|
||||
change_list();
|
||||
advance_and_notify(*r);
|
||||
for (auto& list : lists)
|
||||
advance_and_notify(*list.get_realm());
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
REQUIRE_INDICES(changes[i].insertions, 3);
|
||||
|
Loading…
x
Reference in New Issue
Block a user