-
Notifications
You must be signed in to change notification settings - Fork 229
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
base: main
Are you sure you want to change the base?
Conversation
@@ -181,11 +157,23 @@ impl Record { | |||
} | |||
} | |||
|
|||
impl From<Record> for RemoteSettingsRecord { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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>> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
components/suggest/src/rs.rs
Outdated
}) | ||
} | ||
|
||
fn client_for_collection(&self, collection: Collection) -> &remote_settings::RemoteSettings { | ||
fn client_for_collection(&self, collection: Collection) -> &Arc<RemoteSettingsClient> { |
There was a problem hiding this comment.
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.
components/suggest/src/rs.rs
Outdated
}; | ||
if last_modified != response.last_modified { | ||
dao.write_cached_rs_data(collection.name(), &response); | ||
let _ = client.sync(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
components/suggest/src/rs.rs
Outdated
fn to_json_map(&self) -> Map<String, Value> { | ||
match serde_json::to_value(self) { | ||
Ok(Value::Object(map)) => map, | ||
_ => Map::new(), |
There was a problem hiding this comment.
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
.
93bd3d2
to
4e99448
Compare
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 |
4e99448
to
5ddb547
Compare
5ddb547
to
f584af2
Compare
I see that the other PRs are merged, so i rebased and made changes 🙂 |
Pull Request checklist
[ci full]
to the PR title.Branch builds: add
[firefox-android: branch-name]
to the PR title.