8000 Allow multiple app instances with the same ID but different base URLs by kmorkos · Pull Request #6480 · realm/realm-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow multiple app instances with the same ID but different base URLs #6480

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

Merged
merged 13 commits into from
May 4, 2023

Conversation

kmorkos
Copy link
Contributor
@kmorkos kmorkos commented Apr 6, 2023

What, How & Why?

Updates s_apps_cache to be a multi-level map keyed off the base URL in addition to app ID. To avoid making this a breaking change, get_cached_app now optionally accepts the base URL as a second parameter. If it is not provided then the behavior is non-deterministic when there's multiple app configs with the same app ID but different base URLs (but still no worse than the current behavior).

Also worth noting that the changes to get_cached_app are not exposed in the C api since that method is being removed as per #5644 (comment)

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • C-API, if public C++ API changed.

@cla-bot
Copy link
cla-bot bot commented Apr 6, 2023

Realm welcomes all contributions! The only requirement we have is that, like many other projects, we need to have a Contributor License Agreement (CLA) in place before we can accept any external code. Our own CLA is a modified version of the Apache Software Foundation’s CLA. Our records show that CLA has not been signed by @kmorkos. Please submit your CLA electronically using our Google form so we can accept your submissions. After signing the CLA you can recheck this PR with a @cla-bot check comment. The GitHub usernames you file there will need to match that of your Pull Requests. If you have any questions or cannot file the CLA electronically, make a comment here and we will be happy to help you out.

@kmorkos
Copy link
Contributor Author
kmorkos commented Apr 6, 2023

@cla-bot check

@cla-bot cla-bot bot added the cla: yes label Apr 6, 2023
@cla-bot
Copy link
cla-bot bot commented Apr 6, 2023

The cla-bot has been summoned, and re-checked this pull request!

@kmorkos kmorkos marked this pull request as ready for review April 6, 2023 20:56
@kmorkos kmorkos requested review from jbreams and michael-wb April 6, 2023 20:56
Copy link
Contributor
@jbreams jbreams left a comment

Choose a reason for hiding this comment

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

Should we also remove the deprecated C API function for get_cached_app?

CHANGELOG.md Outdated
@@ -1,8 +1,7 @@
# NEXT RELEASE

### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* None.
* Allow multiple app instances with the same ID but different base URLs ([#6480](https://github.com/realm/realm-core/pull/6480))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add something here about supporting multiple app instances via get_shared_app() and get_cached_app() specifically - the changelog is used by the SDKs to know when/what to change when they're adopting a version of core and to communicate to users what they'll need to change.

Copy link
Contributor Auth 10000 or

Choose a reason for hiding this comment

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

Good call, will update 👍🏼

@kmorkos kmorkos requested a review from jbreams April 6, 2023 21:49
Copy link
Contributor
@michael-wb michael-wb left a comment

Choose a reason for hiding this comment

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

LGTM - just a few minor comments
Should we also remove realm_app_get(), since that function is deprecated as well?


auto config2 = base_config;
config2.app_id = "app1";
config2.base_url = "https://realm.mongodb.com";
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment that this is supposed to equal the default_base_url value

auto app2_2 = App::get_cached_app(config3.app_id, config3.base_url);
auto app2_3 = App::get_shared_app(config4, sync_config);
auto app2_4 = App::get_cached_app(config3.app_id);

Copy link
Contributor

Choose a reason for hiding this comment

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

So we verify getting the cached app when there are two different URLs, let's add one more:
auto app2_5 = App::get_cached_app(config4.app_id, config4.base_url);
And then check that app2_3 == app2_5

Also auto app2_6 = App::get_cached_app(config4.app_id, "https://some.different.url");
And then check that app2_6 == nullptr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we verify getting the cached app when there are two different URLs, let's add one more:
auto app2_5 = App::get_cached_app(config4.app_id, config4.base_url);
And then check that app2_3 == app2_5

This is the same scenario as CHECK(app1_1 == app1_3); above

Also auto app2_6 = App::get_cached_app(config4.app_id, "https://some.different.url");
And then check that app2_6 == nullptr

I'll add this one 👍🏼

return it->second;
const auto& apps_by_url = it->second;

auto app_it = base_url.has_value() ? apps_by_url.find(*base_url) : apps_by_url.begin();
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to call has_value() - since it's already evaluating to a bool, you can do this:
auto app_it = base_url ? apps_by_url.find(*base_url) : apps_by_url.begin();

@kmorkos
Copy link
Contributor Author
kmorkos commented May 4, 2023

Should we also remove realm_app_get(), since that function is deprecated as well?

Looks like that one is no longer used either according to my github search, I can remove it here as well

@kmorkos kmorkos merged commit 7817506 into master May 4, 2023
@kmorkos kmorkos deleted the km/app-diff-base-urls branch May 4, 2023 19:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Connect client to two different sync servers with the same app id
3 participants
0