diff --git a/src/impl/realm_coordinator.cpp b/src/impl/realm_coordinator.cpp index cc2800b0..b9ae3e98 100644 --- a/src/impl/realm_coordinator.cpp +++ b/src/impl/realm_coordinator.cpp @@ -66,7 +66,7 @@ std::shared_ptr RealmCoordinator::get_realm(Realm::Config config) std::lock_guard lock(m_realm_mutex); if ((!m_config.read_only && !m_notifier) || (m_config.read_only && m_weak_realm_notifiers.empty())) { m_config = config; - if (!config.read_only && !m_notifier) { + if (!config.read_only && !m_notifier && config.automatic_change_notifications) { try { m_notifier = std::make_unique(*this); } @@ -202,7 +202,9 @@ void RealmCoordinator::clear_cache() void RealmCoordinator::send_commit_notifications() { REALM_ASSERT(!m_config.read_only); - m_notifier->notify_others(); + if (m_notifier) { + m_notifier->notify_others(); + } } void RealmCoordinator::pin_version(uint_fast64_t version, uint_fast32_t index) diff --git a/src/shared_realm.cpp b/src/shared_realm.cpp index 272a3367..16250c23 100644 --- a/src/shared_realm.cpp +++ b/src/shared_realm.cpp @@ -35,13 +35,14 @@ using namespace realm::_impl; Realm::Config::Config(const Config& c) : path(c.path) +, encryption_key(c.encryption_key) +, schema_version(c.schema_version) +, migration_function(c.migration_function) , read_only(c.read_only) , in_memory(c.in_memory) , cache(c.cache) , disable_format_upgrade(c.disable_format_upgrade) -, encryption_key(c.encryption_key) -, schema_version(c.schema_version) -, migration_function(c.migration_function) +, automatic_change_notifications(c.automatic_change_notifications) { if (c.schema) { schema = std::make_unique(*c.schema); diff --git a/src/shared_realm.hpp b/src/shared_realm.hpp index 2360a225..5bd90aac 100644 --- a/src/shared_realm.hpp +++ b/src/shared_realm.hpp @@ -47,20 +47,40 @@ namespace realm { public: typedef std::function MigrationFunction; - struct Config - { + struct Config { std::string path; - bool read_only = false; - bool in_memory = false; - bool cache = true; - bool disable_format_upgrade = false; + // User-supplied encryption key. Must be either empty or 64 bytes. std::vector encryption_key; + // Optional schema for the file. If nullptr, the existing schema + // from the file opened will be used. If present, the file will be + // migrated to the schema if needed. std::unique_ptr schema; uint64_t schema_version; MigrationFunction migration_function; + bool read_only = false; + bool in_memory = false; + + // The following are intended for internal/testing purposes and + // should not be publically exposed in binding APIs + + // If false, always return a new Realm instance, and don't return + // that Realm instance for other requests for a cached Realm. Useful + // for dynamic Realms and for tests that need multiple instances on + // one thread + bool cache = true; + // Throw an exception rather than automatically upgrading the file + // format. Used by the browser to warn the user that it'll modify + // the file. + bool disable_format_upgrade = false; + // Disable the background worker thread for producing change + // notifications. Useful for tests for those notifications so that + // everything can be done deterministically on one thread, and + // speeds up tests that don't need notifications. + bool automatic_change_notifications = true; + Config(); Config(Config&&); Config(const Config& c);