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

[DISCO-3211] Suggest: move to new remote settings API #6598

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tiftran
Copy link
Contributor

@tiftran tiftran commented Feb 19, 2025

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

Branch builds: add [firefox-android: branch-name] to the PR title.

@tiftran tiftran requested a review from a team February 19, 2025 07:46
@@ -181,11 +157,23 @@ impl Record {
}
}

impl From<Record> for RemoteSettingsRecord {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cargo clippy said impl From is preferred over Into

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, Rust will automatically generate the Into if you define a From.

@@ -214,6 +202,15 @@ pub(crate) enum SuggestRecord {
Geonames,
}

impl SuggestRecord {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels a little goofy just so that we can use Record to get_attachment, but setting fields to Map::new( ) also felt weird

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, slightly goofy but this makes sense to me.

Copy link
Contributor

@bendk bendk left a comment

Choose a reason for hiding this comment

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

This looks great. I had some minor suggestions, but the only real issue is how we land this. I'm marking this Request Changes just because I think we should land that preparatory PR I mentioned to make dealing with the breaking changes easier.

@@ -98,19 +98,14 @@ impl SuggestStoreBuilder {
}

#[handle_error(Error)]
pub fn build(&self) -> SuggestApiResult<Arc<SuggestStore>> {
pub fn build(&self, rs_service: &RemoteSettingsService) -> SuggestApiResult<Arc<SuggestStore>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

One thing that we haven't talked about is that this is going to be a breaking change for all applications, and it might not be so simple to fix. I'm not sure they all have started using the new remote settings API and have a RemoteSettingsService ready to give us.

To make the transition easy, could you open a second PR that changes this signature to something like this:

#[uniffi::method(default(rs_service=None))]
pub fn build(&self, rs_service: Option<Arc<RemoteSettingsService>>)

That PR doesn't need to do actually do anything with rs_service. The point is to give us a decent way to merge all the changes:

  • Merge the above, non-breaking, change.
  • Get all consumers to start passing in the rs_service
  • Merge your actual PR, which technically will be a breaking change since rs_service is no longer optional, but it shouldn't be much work to fix the consumer apps. Maybe they won't need any changes at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

remote_settings_server and remote_settings_bucket_name can be removed from SuggestStoreBuilder too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually why not make rs_service a method on SuggestStoreBuilder instead of an arg to build?

std::fs::copy(starter_db_path, &db_path).expect("Error copying starter DB file");
SuggestStore::new(&db_path.to_string_lossy(), None).expect("Error building store")
SuggestStore::new(&db_path.to_string_lossy(), remote_settings_service)
.expect("Error building store")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Thanks for keeping this code up to date.

})
}

fn client_for_collection(&self, collection: Collection) -> &remote_settings::RemoteSettings {
fn client_for_collection(&self, collection: Collection) -> &Arc<RemoteSettingsClient> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this could just be a &RemoteSettingsClient. The Arc makes me think it might be cloned to create a new reference, but I don't think you ever do that.

};
if last_modified != response.last_modified {
dao.write_cached_rs_data(collection.name(), &response);
let _ = client.sync();
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be client.sync()?, that way errors get propagated up.

@@ -181,11 +157,23 @@ impl Record {
}
}

impl From<Record> for RemoteSettingsRecord {
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, Rust will automatically generate the Into if you define a From.

@@ -214,6 +202,15 @@ pub(crate) enum SuggestRecord {
Geonames,
}

impl SuggestRecord {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, slightly goofy but this makes sense to me.

fn to_json_map(&self) -> Map<String, Value> {
match serde_json::to_value(self) {
Ok(Value::Object(map)) => map,
_ => Map::new(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this branch could be unreachable!(). I think we can safely say that serde will always be able to to deserialize to Value::Object.

@tiftran
Copy link
Contributor Author

tiftran commented Feb 19, 2025

I see that there are a couple of PRs that will slightly change this one, I will wait and see when those merge and change accordingly

@tiftran
Copy link
Contributor Author

tiftran commented Feb 26, 2025

I see that the other PRs are merged, so i rebased and made changes 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants