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
Fixes DISCO-2637: Replace SuggestionQuery
options with providers
. [firefox-android: linabutler/DISCO-2637] [firefox-ios: linabutler/DISCO-2637]
#5867
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #5867 +/- ##
==========================================
- Coverage 36.72% 36.71% -0.01%
==========================================
Files 348 348
Lines 33532 33541 +9
==========================================
Hits 12313 12313
- Misses 21219 21228 +9
☔ View full report in Codecov by Sentry. |
5309e7d
to
29b2c81
Compare
This commit fixes the breaking change introduced in mozilla/application-services#5867.
SuggestionQuery
options with providers
.SuggestionQuery
options with providers
. [firefox-android: linabutler/DISCO-2637]
:url | ||
) | ||
RETURNING id", | ||
SuggestionProvider::Amo as u8 |
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.
The SuggestionProvider
variants are all integers, so, as with providers_to_sql_list
above, we can safely interpolate them directly into the query string, without worrying about SQL injection. This is a trick we use in Places, too! ✨
pub fn fetch_suggestions(&self, query: &SuggestionQuery) -> Result<Vec<Suggestion>> { | ||
let (keyword_prefix, keyword_suffix) = split_keyword(&query.keyword); | ||
|
||
let (mut statement, params) = if query.providers.contains(&SuggestionProvider::Pocket) { |
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.
Pocket keywords use a separate query, so, if we aren't matching Pocket suggestions, we can skip querying pocket_keywords
entirely.
That also means we end up with a dynamically-sized list of params
—two for Pocket; one for non-Pocket—so we have to use a Vec<(&str, &dyn ToSql)>
to hold them.
@@ -258,7 +279,9 @@ impl<'a> SuggestDao<'a> { | |||
} | |||
} | |||
} | |||
)?.into_iter().flatten().collect()) | |||
)?.flat_map(Result::transpose).collect::<Result<_>>()?; |
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 transformation filters out the None
s from our query_and_then(...)
iterator, then accumulates the remaining suggestions into a vector. It leans on a few iterator helpers to do this:
transpose
turns aResult<Option<Suggestion>>
into anOption<Result<Suggestion>>
.- An
Option
is an iterator—it yields zero elements if it'sNone
, and one if it'sSome
—so we can use it withflat_map
to unwrap optionals. This turns our iterator ofOption<Result<Suggestion>>
into an iterator ofResult<Suggestion>
. collect::<Result<_>>
accumulates the iterator ofResult<Suggestion>
into aResult<Vec<Suggestion>>
.
This commit fixes the breaking change introduced in mozilla/application-services#5867.
SuggestionQuery
options with providers
. [firefox-android: linabutler/DISCO-2637]SuggestionQuery
options with providers
. [firefox-android: linabutler/DISCO-2637] [firefox-ios: linabutler/DISCO-2637]
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.
LGTM. Thanks!
I wonder if we could use a "cheaper" construct for SuggestionQuery.providers
. Creating a new vector (despite the providers mostly remaining the same) for each query seems a bit wasteful to me. Would a bitflag fit the bill? I am thinking of this:
use bitflags::bitflags;
bitflags! {
pub struct Providers: u32 {
const Amp = 1;
const Wikipedia = 1 << 1;
const Pocket = 1 << 2;
const Amo = 1 << 3;
}
}
pub struct SuggestionQuery {
pub keyword: String,
pub providers: Providers,
}
// For mobile
let query = SuggestionQuery {
keyword: "foo".to_own(),
providers = Providers::Amp | Providers::Wikipedia,
};
if query.providers.contains(Providers::Pocket) {
} else ...
WDYT?
Thanks for the review! I thought bitflags—or even a set—would be perfect here, too! Unfortunately, they're tricky to do with UniFFI. Neither UDL nor UniFFI's serialization format supports custom values for fieldless enums, so I don't think it would be possible today for Swift, Kotlin, or JS to pass a bitmask, and have Rust see the same value. We could use a custom type to work around that, but then we couldn't use the |
Bummer. Yep, the FFI limitations! If we use an opaque |
This commit removes the `include_sponsored` and `include_non_sponsored` options, and replaces them with a list of `providers`. This lets consumers request specific suggestion types: AMP and Wikipedia only on mobile; and AMP, Wikipedia, and active experiments on Desktop. This is a breaking change.
29b2c81
to
c22e000
Compare
PRs resolving the breaking changes for our consumers:
The process for landing breaking changes like this is roughly:
|
This commit fixes the breaking change introduced in mozilla/application-services#5867.
This commit fixes the breaking change introduced in mozilla/application-services#5867.
* Update A-S to 120.20231014050328. * No bug - Update uses of `SuggestionQuery` in Firefox Suggest. This commit fixes the breaking change introduced in mozilla/application-services#5867. * Fixup build breaking from Nimbus pref-key addition --------- Co-authored-by: MickeyMoz <sebastian@mozilla.com> Co-authored-by: Ryan VanderMeulen <rvandermeulen@mozilla.com> Co-authored-by: Lina Butler <lina@yakshaving.ninja> Co-authored-by: James Hugman <james@hugman.tv> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…1014050328 (#16840) * Auto update SPM with latest rust-component release 120.0.20231014050328 * Bump [v120] Update uses of `SuggestionQuery`. (#16818) This commit fixes the breaking change introduced in mozilla/application-services#5867. * Fixup build breaking from Nimbus pref-key addition --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Lina Butler <lina@yakshaving.ninja> Co-authored-by: James Hugman <james@hugman.tv>
* Update A-S to 120.20231014050328. * No bug - Update uses of `SuggestionQuery` in Firefox Suggest. This commit fixes the breaking change introduced in mozilla/application-services#5867. * Fixup build breaking from Nimbus pref-key addition --------- Co-authored-by: MickeyMoz <sebastian@mozilla.com> Co-authored-by: Ryan VanderMeulen <rvandermeulen@mozilla.com> Co-authored-by: Lina Butler <lina@yakshaving.ninja> Co-authored-by: James Hugman <james@hugman.tv> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Update A-S to 120.20231014050328. * No bug - Update uses of `SuggestionQuery` in Firefox Suggest. This commit fixes the breaking change introduced in mozilla/application-services#5867. * Fixup build breaking from Nimbus pref-key addition --------- Co-authored-by: MickeyMoz <sebastian@mozilla.com> Co-authored-by: Ryan VanderMeulen <rvandermeulen@mozilla.com> Co-authored-by: Lina Butler <lina@yakshaving.ninja> Co-authored-by: James Hugman <james@hugman.tv> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
* Update A-S to 120.20231014050328. * No bug - Update uses of `SuggestionQuery` in Firefox Suggest. This commit fixes the breaking change introduced in mozilla/application-services#5867. * Fixup build breaking from Nimbus pref-key addition --------- Co-authored-by: MickeyMoz <sebastian@mozilla.com> Co-authored-by: Ryan VanderMeulen <rvandermeulen@mozilla.com> Co-authored-by: Lina Butler <lina@yakshaving.ninja> Co-authored-by: James Hugman <james@hugman.tv> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit removes the
include_sponsored
andinclude_non_sponsored
options, and replaces them with a list ofproviders
. This lets consumers request specific suggestion types: AMP and Wikipedia only on mobile; and AMP, Wikipedia, and active experiments on Desktop.This is a backward-incompatible API change.
Pull Request checklist
[ci full]
to the PR title.Branch builds: add
[firefox-android: branch-name]
to the PR title.