suggest: Turn `Suggestion` into an enum.
The previous representation was specific to AMP-Wikipedia.
This commit is contained in:
Родитель
4981e78a9c
Коммит
4b28d41f58
|
@ -6,6 +6,7 @@
|
|||
### 🦊 What's Changed 🦊
|
||||
|
||||
- Backward-incompatible changes to the Suggest database schema to accommodate custom details for providers ([#5745](https://github.com/mozilla/application-services/pull/5745)) and future suggestion types ([#5766](https://github.com/mozilla/application-services/pull/5766)). This only affects prototyping, because we aren't consuming Suggest in any of our products yet.
|
||||
- The `Suggestion` type in the Suggest component has changed from a dictionary to an enum ([#5766](https://github.com/mozilla/application-services/pull/5766)). This only affects prototyping, because we aren't consuming Suggest in any of our products yet.
|
||||
- The Remote Settings `Client::get_attachment()` method now returns a `Vec<u8>` instead of a Viaduct `Response` ([#5764](https://github.com/mozilla/application-services/pull/5764)). You can use the new `Client::get_attachment_raw()` method if you need the `Response`. This is a backward-incompatible change for Rust consumers only; Swift and Kotlin are unaffected.
|
||||
- The Remote Settings client now parses `ETag` response headers from Remote Settings correctly ([#5764](https://github.com/mozilla/application-services/pull/5764)).
|
||||
|
||||
|
|
|
@ -25,10 +25,6 @@ use crate::{
|
|||
/// from the Suggest Remote Settings collection.
|
||||
pub const LAST_INGEST_META_KEY: &str = "last_quicksuggest_ingest";
|
||||
|
||||
/// A list of [`Suggestion::iab_category`] values used to distinguish
|
||||
/// non-sponsored suggestions.
|
||||
pub const NONSPONSORED_IAB_CATEGORIES: &[&str] = &["5 - Education"];
|
||||
|
||||
/// The database connection type.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) enum ConnectionType {
|
||||
|
@ -158,20 +154,16 @@ impl<'a> SuggestDao<'a> {
|
|||
":suggestion_id": suggestion_id
|
||||
},
|
||||
|row| {
|
||||
let iab_category = row.get::<_, String>("iab_category")?;
|
||||
let is_sponsored = !NONSPONSORED_IAB_CATEGORIES.contains(&iab_category.as_str());
|
||||
Ok(Suggestion {
|
||||
Ok(Suggestion::Amp {
|
||||
block_id: row.get("block_id")?,
|
||||
advertiser: row.get("advertiser")?,
|
||||
iab_category,
|
||||
is_sponsored,
|
||||
iab_category: row.get("iab_category")?,
|
||||
title,
|
||||
url,
|
||||
full_keyword: full_keyword(keyword, &keywords),
|
||||
icon: row.get("icon")?,
|
||||
impression_url: row.get("impression_url")?,
|
||||
click_url: row.get("click_url")?,
|
||||
provider
|
||||
})
|
||||
}
|
||||
)
|
||||
|
@ -187,18 +179,11 @@ impl<'a> SuggestDao<'a> {
|
|||
},
|
||||
true,
|
||||
)?;
|
||||
Ok(Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Wikipedia".to_string(),
|
||||
iab_category: "5 - Education".to_string(),
|
||||
is_sponsored: false,
|
||||
Ok(Suggestion::Wikipedia {
|
||||
title,
|
||||
url,
|
||||
full_keyword: full_keyword(keyword, &keywords),
|
||||
icon,
|
||||
impression_url: None,
|
||||
click_url: None,
|
||||
provider
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,30 +10,16 @@ mod keyword;
|
|||
mod rs;
|
||||
mod schema;
|
||||
mod store;
|
||||
mod suggestion;
|
||||
|
||||
pub use error::SuggestApiError;
|
||||
use rs::SuggestionProvider;
|
||||
pub use store::{SuggestIngestionConstraints, SuggestStore};
|
||||
pub use suggestion::Suggestion;
|
||||
|
||||
pub(crate) type Result<T> = std::result::Result<T, error::Error>;
|
||||
pub type SuggestApiResult<T> = std::result::Result<T, error::SuggestApiError>;
|
||||
|
||||
/// A suggestion from the database to show in the address bar.
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct Suggestion {
|
||||
pub block_id: i64,
|
||||
pub advertiser: String,
|
||||
pub iab_category: String,
|
||||
pub is_sponsored: bool,
|
||||
pub full_keyword: String,
|
||||
pub title: String,
|
||||
pub url: String,
|
||||
pub icon: Option<Vec<u8>>,
|
||||
pub impression_url: Option<String>,
|
||||
pub click_url: Option<String>,
|
||||
pub provider: SuggestionProvider,
|
||||
}
|
||||
|
||||
/// A query for suggestions to show in the address bar.
|
||||
#[derive(Debug, Default)]
|
||||
pub struct SuggestionQuery {
|
||||
|
|
|
@ -141,8 +141,8 @@ impl<S> SuggestStoreInner<S> {
|
|||
Ok(suggestions
|
||||
.into_iter()
|
||||
.filter(|suggestion| {
|
||||
(suggestion.is_sponsored && query.include_sponsored)
|
||||
|| (!suggestion.is_sponsored && query.include_non_sponsored)
|
||||
(suggestion.is_sponsored() && query.include_sponsored)
|
||||
|| (!suggestion.is_sponsored() && query.include_non_sponsored)
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
@ -469,22 +469,16 @@ mod tests {
|
|||
assert_eq!(dao.get_meta::<u64>(LAST_INGEST_META_KEY)?, Some(15));
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Los Pollos Hermanos",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "los",
|
||||
Amp {
|
||||
title: "Los Pollos Hermanos - Albuquerque",
|
||||
url: "https://www.lph-nm.biz",
|
||||
icon: None,
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "los",
|
||||
block_id: 0,
|
||||
advertiser: "Los Pollos Hermanos",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
|
@ -560,12 +554,7 @@ mod tests {
|
|||
store.dbs()?.reader.read(|dao| {
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "lasagna",
|
||||
Amp {
|
||||
title: "Lasagna Come Out Tomorrow",
|
||||
url: "https://www.lasagna.restaurant",
|
||||
icon: Some(
|
||||
|
@ -584,25 +573,19 @@ mod tests {
|
|||
110,
|
||||
],
|
||||
),
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "lasagna",
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
.assert_debug_eq(&dao.fetch_by_keyword("la")?);
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "penne",
|
||||
Amp {
|
||||
title: "Penne for Your Thoughts",
|
||||
url: "https://penne.biz",
|
||||
icon: Some(
|
||||
|
@ -621,13 +604,12 @@ mod tests {
|
|||
110,
|
||||
],
|
||||
),
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "penne",
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
|
@ -682,22 +664,16 @@ mod tests {
|
|||
store.dbs()?.reader.read(|dao| {
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "lasagna",
|
||||
Amp {
|
||||
title: "Lasagna Come Out Tomorrow",
|
||||
url: "https://www.lasagna.restaurant",
|
||||
icon: None,
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "lasagna",
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
|
@ -763,22 +739,16 @@ mod tests {
|
|||
assert_eq!(dao.get_meta(LAST_INGEST_META_KEY)?, Some(15u64));
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "lasagna",
|
||||
Amp {
|
||||
title: "Lasagna Come Out Tomorrow",
|
||||
url: "https://www.lasagna.restaurant",
|
||||
icon: None,
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "lasagna",
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
|
@ -832,44 +802,32 @@ mod tests {
|
|||
assert!(dao.fetch_by_keyword("la")?.is_empty());
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Los Pollos Hermanos",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "los pollos",
|
||||
Amp {
|
||||
title: "Los Pollos Hermanos - Now Serving at 14 Locations!",
|
||||
url: "https://www.lph-nm.biz",
|
||||
icon: None,
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "los pollos",
|
||||
block_id: 0,
|
||||
advertiser: "Los Pollos Hermanos",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
.assert_debug_eq(&dao.fetch_by_keyword("los ")?);
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "penne",
|
||||
Amp {
|
||||
title: "Penne for Your Thoughts",
|
||||
url: "https://penne.biz",
|
||||
icon: None,
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "penne",
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
|
@ -998,12 +956,7 @@ mod tests {
|
|||
assert_eq!(dao.get_meta(LAST_INGEST_META_KEY)?, Some(35u64));
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "lasagna",
|
||||
Amp {
|
||||
title: "Lasagna Come Out Tomorrow",
|
||||
url: "https://www.lasagna.restaurant",
|
||||
icon: Some(
|
||||
|
@ -1026,25 +979,19 @@ mod tests {
|
|||
110,
|
||||
],
|
||||
),
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "lasagna",
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
.assert_debug_eq(&dao.fetch_by_keyword("la")?);
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Los Pollos Hermanos",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "los",
|
||||
Amp {
|
||||
title: "Los Pollos Hermanos - Albuquerque",
|
||||
url: "https://www.lph-nm.biz",
|
||||
icon: Some(
|
||||
|
@ -1066,13 +1013,12 @@ mod tests {
|
|||
110,
|
||||
],
|
||||
),
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "los",
|
||||
block_id: 0,
|
||||
advertiser: "Los Pollos Hermanos",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]]
|
||||
|
@ -1392,12 +1338,7 @@ mod tests {
|
|||
},
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "lasagna",
|
||||
Amp {
|
||||
title: "Lasagna Come Out Tomorrow",
|
||||
url: "https://www.lasagna.restaurant",
|
||||
icon: Some(
|
||||
|
@ -1416,13 +1357,12 @@ mod tests {
|
|||
110,
|
||||
],
|
||||
),
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "lasagna",
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
|
@ -1436,12 +1376,7 @@ mod tests {
|
|||
},
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
is_sponsored: true,
|
||||
full_keyword: "lasagna",
|
||||
Amp {
|
||||
title: "Lasagna Come Out Tomorrow",
|
||||
url: "https://www.lasagna.restaurant",
|
||||
icon: Some(
|
||||
|
@ -1460,13 +1395,12 @@ mod tests {
|
|||
110,
|
||||
],
|
||||
),
|
||||
impression_url: Some(
|
||||
"https://example.com/impression_url",
|
||||
),
|
||||
click_url: Some(
|
||||
"https://example.com/click_url",
|
||||
),
|
||||
provider: Amp,
|
||||
full_keyword: "lasagna",
|
||||
block_id: 0,
|
||||
advertiser: "Good Place Eats",
|
||||
iab_category: "8 - Food & Drink",
|
||||
impression_url: "https://example.com/impression_url",
|
||||
click_url: "https://example.com/click_url",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
|
@ -1524,12 +1458,7 @@ mod tests {
|
|||
},
|
||||
expect![[r#"
|
||||
[
|
||||
Suggestion {
|
||||
block_id: 0,
|
||||
advertiser: "Wikipedia",
|
||||
iab_category: "5 - Education",
|
||||
is_sponsored: false,
|
||||
full_keyword: "california",
|
||||
Wikipedia {
|
||||
title: "California",
|
||||
url: "https://wikipedia.org/California",
|
||||
icon: Some(
|
||||
|
@ -1548,9 +1477,7 @@ mod tests {
|
|||
110,
|
||||
],
|
||||
),
|
||||
impression_url: None,
|
||||
click_url: None,
|
||||
provider: Wikipedia,
|
||||
full_keyword: "california",
|
||||
},
|
||||
]
|
||||
"#]],
|
||||
|
|
|
@ -21,18 +21,25 @@ enum SuggestionProvider {
|
|||
"Wikipedia",
|
||||
};
|
||||
|
||||
dictionary Suggestion {
|
||||
i64 block_id;
|
||||
string advertiser;
|
||||
string iab_category;
|
||||
boolean is_sponsored;
|
||||
string full_keyword;
|
||||
string title;
|
||||
string url;
|
||||
sequence<u8>? icon;
|
||||
string? impression_url;
|
||||
string? click_url;
|
||||
SuggestionProvider provider;
|
||||
[Enum]
|
||||
interface Suggestion {
|
||||
Amp(
|
||||
string title,
|
||||
string url,
|
||||
sequence<u8>? icon,
|
||||
string full_keyword,
|
||||
i64 block_id,
|
||||
string advertiser,
|
||||
string iab_category,
|
||||
string impression_url,
|
||||
string click_url
|
||||
);
|
||||
Wikipedia(
|
||||
string title,
|
||||
string url,
|
||||
sequence<u8>? icon,
|
||||
string full_keyword
|
||||
);
|
||||
};
|
||||
|
||||
dictionary SuggestionQuery {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
/// A suggestion from the database to show in the address bar.
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum Suggestion {
|
||||
Amp {
|
||||
title: String,
|
||||
url: String,
|
||||
icon: Option<Vec<u8>>,
|
||||
full_keyword: String,
|
||||
block_id: i64,
|
||||
advertiser: String,
|
||||
iab_category: String,
|
||||
impression_url: String,
|
||||
click_url: String,
|
||||
},
|
||||
Wikipedia {
|
||||
title: String,
|
||||
url: String,
|
||||
icon: Option<Vec<u8>>,
|
||||
full_keyword: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl Suggestion {
|
||||
/// Returns `true` if the suggestion is sponsored.
|
||||
pub(crate) fn is_sponsored(&self) -> bool {
|
||||
matches!(self, Self::Amp { .. })
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче