Skip to content
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

[v10] Cache Realm instances #3325

Merged
merged 2 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ x.x.x Release notes (yyyy-MM-dd)
* Fixed a bug where an integer could prematurely be converted & returned as a `Long` instead of a `number`. ([#3205](https://github.com/realm/realm-js/pull/3205), since v10.0.0-beta.1)
* TS declaration for `isLoggedIn` added to `User`. ([#3294](https://github.com/realm/realm-js/pull/3294))
* Fixed error `Attempted import error: 'invalidateCache' is not exported from './util' (imported as 'util').` ([#3314](https://github.com/realm/realm-js/issues/3314))
* Fixed a bug preventing caching of Realm instances. In certain cases, the Realm file would grow without any new objects added.

### Compatibility
* MongoDB Realm Cloud.
Expand Down
1 change: 1 addition & 0 deletions src/js_realm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ bool RealmClass<T>::get_realm_config(ContextType ctx, size_t argc, const ValueTy
}
}

config.cache = true;
config.path = normalize_realm_path(config.path);
ensure_directory_exists_for_file(config.path);
return schema_updated;
Expand Down
3 changes: 2 additions & 1 deletion tests/js/realm-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1538,8 +1538,9 @@ module.exports = {
testManualCompactMultipleInstances: function() {
const realm1 = new Realm({schema: [schemas.StringOnly]});
const realm2 = new Realm({schema: [schemas.StringOnly]});
// realm1 and realm2 are the same Realm instance
realm2.objects('StringOnlyObject');
TestCase.assertFalse(realm1.compact());
TestCase.assertTrue(realm1.compact());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the test here is in the "limitation" of compact(): "Compaction will not occur if other Realm instances exist." Maybe add a comment about this?

And a question: What happens to realm2 when realm1 is closed (e.g. realm1.close())?

},

testRealmDeleteFileDefaultConfigPath: function() {
Expand Down