diff --git a/shared_realm.cpp b/shared_realm.cpp index 8b003d30..77d39c21 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -198,7 +198,9 @@ bool Realm::update_schema(std::unique_ptr schema, uint64_t version) auto migration_function = [&](Group*, Schema&) { SharedRealm old_realm(new Realm(old_config)); auto updated_realm = shared_from_this(); - m_config.migration_function(old_realm, updated_realm); + if (m_config.migration_function) { + m_config.migration_function(old_realm, updated_realm); + } }; try { @@ -438,6 +440,19 @@ void RealmCache::cache_realm(SharedRealm &realm, std::thread::id thread_id) } } +void RealmCache::invalidate_all() +{ + std::lock_guard lock(m_mutex); + + for (auto &path_realms:m_cache) { + for (auto &realm_iter:path_realms.second) { + if (auto realm = realm_iter.second.lock()) { + realm->invalidate(); + } + } + } +} + void RealmCache::clear() { std::lock_guard lock(m_mutex); diff --git a/shared_realm.hpp b/shared_realm.hpp index aa19071e..4721e37e 100644 --- a/shared_realm.hpp +++ b/shared_realm.hpp @@ -131,6 +131,7 @@ namespace realm { SharedRealm get_any_realm(const std::string &path); void remove(const std::string &path, std::thread::id thread_id); void cache_realm(SharedRealm &realm, std::thread::id thread_id = std::this_thread::get_id()); + void invalidate_all(); void clear(); private: