Skip to content

Commit d64ec13

Browse files
authored
[DISCO-3505] remove fakespot support for suggest (#7277)
* [DISCO-3505] remove fakespot support for suggest * benchmark changes * feedback changes
1 parent 6a5db72 commit d64ec13

File tree

15 files changed

+26
-940
lines changed

15 files changed

+26
-940
lines changed

components/suggest/src/benchmarks/client.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ impl RemoteSettingsBenchmarkClient {
3838
})?,
3939
rs::Collection::Other,
4040
)?;
41-
new_benchmark_client.fetch_data_with_client(
42-
remote_settings::RemoteSettings::new(remote_settings::RemoteSettingsConfig {
43-
server: None,
44-
bucket_name: None,
45-
collection_name: rs::Collection::Fakespot.name().to_owned(),
46-
server_url: None,
47-
})?,
48-
rs::Collection::Fakespot,
49-
)?;
5041
Ok(new_benchmark_client)
5142
}
5243

components/suggest/src/benchmarks/ingest.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,6 @@ pub fn all_benchmarks() -> Vec<(&'static str, IngestBenchmark)> {
172172
true,
173173
),
174174
),
175-
(
176-
"ingest-fakespot",
177-
IngestBenchmark::new(SuggestionProvider::Fakespot, false),
178-
),
179-
(
180-
"ingest-again-fakespot",
181-
IngestBenchmark::new(SuggestionProvider::Fakespot, true),
182-
),
183175
]
184176
}
185177

@@ -191,8 +183,6 @@ pub fn print_debug_ingestion_sizes() {
191183
);
192184
store
193185
.ingest(SuggestIngestionConstraints {
194-
// Uncomment to measure the size for a specific provider
195-
// providers: Some(vec![crate::SuggestionProvider::Fakespot]),
196186
..SuggestIngestionConstraints::default()
197187
})
198188
.unwrap();

components/suggest/src/benchmarks/query.rs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -58,59 +58,7 @@ impl BenchmarkWithInput for QueryBenchmark {
5858

5959
pub fn all_benchmarks() -> Vec<(&'static str, QueryBenchmark)> {
6060
vec![
61-
// Fakespot queries, these attempt to perform prefix matches with various character
62-
// lengths.
63-
//
6461
// The query code will only do a prefix match if the total input length is > 3 chars.
65-
// Therefore, to test shorter prefixes we use 2-term queries.
66-
(
67-
"query-fakespot-hand-s",
68-
QueryBenchmark {
69-
provider: SuggestionProvider::Fakespot,
70-
query: "hand s",
71-
should_match: true,
72-
}
73-
),
74-
(
75-
"query-fakespot-hand-sa",
76-
QueryBenchmark {
77-
provider: SuggestionProvider::Fakespot,
78-
query: "hand sa",
79-
should_match: true,
80-
}
81-
),
82-
(
83-
"query-fakespot-hand-san",
84-
QueryBenchmark {
85-
provider: SuggestionProvider::Fakespot,
86-
query: "hand san",
87-
should_match: true,
88-
}
89-
),
90-
(
91-
"query-fakespot-sani",
92-
QueryBenchmark {
93-
provider: SuggestionProvider::Fakespot,
94-
query: "sani",
95-
should_match: true,
96-
}
97-
),
98-
(
99-
"query-fakespot-sanit",
100-
QueryBenchmark {
101-
provider: SuggestionProvider::Fakespot,
102-
query: "sanit",
103-
should_match: true,
104-
}
105-
),
106-
(
107-
"query-fakespot-saniti",
108-
QueryBenchmark {
109-
provider: SuggestionProvider::Fakespot,
110-
query: "saniti",
111-
should_match: false,
112-
},
113-
),
11462

11563
// weather: no matches
11664
(

components/suggest/src/db.rs

Lines changed: 2 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ use sql_support::{open_database, repeat_sql_vars, ConnExt};
1717
use crate::{
1818
config::{SuggestGlobalConfig, SuggestProviderConfig},
1919
error::RusqliteResultExt,
20-
fakespot,
2120
geoname::GeonameCache,
2221
provider::{AmpMatchingStrategy, SuggestionProvider},
2322
query::{full_keywords_to_fts_content, FtsQuery},
2423
rs::{
2524
DownloadedAmoSuggestion, DownloadedAmpSuggestion, DownloadedDynamicRecord,
26-
DownloadedDynamicSuggestion, DownloadedFakespotSuggestion, DownloadedMdnSuggestion,
27-
DownloadedWikipediaSuggestion, Record, SuggestRecordId, SuggestRecordType,
25+
DownloadedDynamicSuggestion, DownloadedMdnSuggestion, DownloadedWikipediaSuggestion,
26+
Record, SuggestRecordId, SuggestRecordType,
2827
},
2928
schema::{clear_database, SuggestConnectionInitializer},
3029
suggestion::{cook_raw_suggestion_url, FtsMatchInfo, Suggestion},
@@ -762,113 +761,6 @@ impl<'a> SuggestDao<'a> {
762761
Ok(suggestions)
763762
}
764763

765-
/// Fetches Fakespot suggestions
766-
pub fn fetch_fakespot_suggestions(&self, query: &SuggestionQuery) -> Result<Vec<Suggestion>> {
767-
let fts_query = query.fts_query();
768-
let sql = r#"
769-
SELECT
770-
s.id,
771-
s.title,
772-
s.url,
773-
s.score,
774-
f.fakespot_grade,
775-
f.product_id,
776-
f.rating,
777-
f.total_reviews,
778-
i.data,
779-
i.mimetype,
780-
f.keywords,
781-
f.product_type
782-
FROM
783-
suggestions s
784-
JOIN
785-
fakespot_fts fts
786-
ON fts.rowid = s.id
787-
JOIN
788-
fakespot_custom_details f
789-
ON f.suggestion_id = s.id
790-
LEFT JOIN
791-
icons i
792-
ON i.id = f.icon_id
793-
WHERE
794-
fakespot_fts MATCH ?
795-
ORDER BY
796-
s.score DESC
797-
"#
798-
.to_string();
799-
800-
// Store the list of results plus the suggestion id for calculating the FTS match info
801-
let mut results =
802-
self.conn
803-
.query_rows_and_then_cached(&sql, (&fts_query.match_arg,), |row| {
804-
let id: usize = row.get(0)?;
805-
let score = fakespot::FakespotScore::new(
806-
&query.keyword,
807-
row.get(10)?,
808-
row.get(11)?,
809-
row.get(3)?,
810-
)
811-
.as_suggest_score();
812-
Result::Ok((
813-
Suggestion::Fakespot {
814-
title: row.get(1)?,
815-
url: row.get(2)?,
816-
score,
817-
fakespot_grade: row.get(4)?,
818-
product_id: row.get(5)?,
819-
rating: row.get(6)?,
820-
total_reviews: row.get(7)?,
821-
icon: row.get(8)?,
822-
icon_mimetype: row.get(9)?,
823-
match_info: None,
824-
},
825-
id,
826-
))
827-
})?;
828-
// Sort the results, then add the FTS match info to the first one
829-
// For performance reasons, this is only calculated for the result with the highest score.
830-
// We assume that only one that will be shown to the user and therefore the only one we'll
831-
// collect metrics for.
832-
results.sort();
833-
if let Some((suggestion, id)) = results.first_mut() {
834-
match suggestion {
835-
Suggestion::Fakespot {
836-
match_info, title, ..
837-
} => {
838-
*match_info = Some(self.fetch_fakespot_fts_match_info(&fts_query, *id, title)?);
839-
}
840-
_ => unreachable!(),
841-
}
842-
}
843-
Ok(results
844-
.into_iter()
845-
.map(|(suggestion, _)| suggestion)
846-
.collect())
847-
}
848-
849-
fn fetch_fakespot_fts_match_info(
850-
&self,
851-
fts_query: &FtsQuery<'_>,
852-
suggestion_id: usize,
853-
title: &str,
854-
) -> Result<FtsMatchInfo> {
855-
let prefix = if fts_query.is_prefix_query {
856-
// If the query was a prefix match query then test if the query without the prefix
857-
// match would have also matched. If not, then this counts as a prefix match.
858-
let sql = "SELECT 1 FROM fakespot_fts WHERE rowid = ? AND fakespot_fts MATCH ?";
859-
let params = (&suggestion_id, &fts_query.match_arg_without_prefix_match);
860-
!self.conn.exists(sql, params)?
861-
} else {
862-
// If not, then it definitely wasn't a prefix match
863-
false
864-
};
865-
866-
Ok(FtsMatchInfo {
867-
prefix,
868-
stemming: fts_query.match_required_stemming(title),
869-
})
870-
}
871-
872764
/// Fetches dynamic suggestions
873765
pub fn fetch_dynamic_suggestions(&self, query: &SuggestionQuery) -> Result<Vec<Suggestion>> {
874766
let Some(suggestion_types) = query
@@ -1114,27 +1006,6 @@ impl<'a> SuggestDao<'a> {
11141006
Ok(())
11151007
}
11161008

1117-
/// Inserts all suggestions from a downloaded Fakespot attachment into the database.
1118-
pub fn insert_fakespot_suggestions(
1119-
&mut self,
1120-
record_id: &SuggestRecordId,
1121-
suggestions: &[DownloadedFakespotSuggestion],
1122-
) -> Result<()> {
1123-
let mut suggestion_insert = SuggestionInsertStatement::new(self.conn)?;
1124-
let mut fakespot_insert = FakespotInsertStatement::new(self.conn)?;
1125-
for suggestion in suggestions {
1126-
let suggestion_id = suggestion_insert.execute(
1127-
record_id,
1128-
&suggestion.title,
1129-
&suggestion.url,
1130-
suggestion.score,
1131-
SuggestionProvider::Fakespot,
1132-
)?;
1133-
fakespot_insert.execute(suggestion_id, suggestion)?;
1134-
}
1135-
Ok(())
1136-
}
1137-
11381009
/// Inserts dynamic suggestion records data into the database.
11391010
pub fn insert_dynamic_suggestions(
11401011
&mut self,
@@ -1295,14 +1166,6 @@ impl<'a> SuggestDao<'a> {
12951166
named_params! { ":record_id": record_id.as_str() },
12961167
)?;
12971168
self.scope.err_if_interrupted()?;
1298-
self.conn.execute_cached(
1299-
"
1300-
DELETE FROM fakespot_fts
1301-
WHERE rowid IN (SELECT id from suggestions WHERE record_id = :record_id)
1302-
",
1303-
named_params! { ":record_id": record_id.as_str() },
1304-
)?;
1305-
self.scope.err_if_interrupted()?;
13061169
self.conn.execute_cached(
13071170
"DELETE FROM suggestions WHERE record_id = :record_id",
13081171
named_params! { ":record_id": record_id.as_str() },
@@ -1677,51 +1540,6 @@ impl<'conn> MdnInsertStatement<'conn> {
16771540
}
16781541
}
16791542

1680-
struct FakespotInsertStatement<'conn>(rusqlite::Statement<'conn>);
1681-
1682-
impl<'conn> FakespotInsertStatement<'conn> {
1683-
fn new(conn: &'conn Connection) -> Result<Self> {
1684-
Ok(Self(conn.prepare(
1685-
"INSERT INTO fakespot_custom_details(
1686-
suggestion_id,
1687-
fakespot_grade,
1688-
product_id,
1689-
keywords,
1690-
product_type,
1691-
rating,
1692-
total_reviews,
1693-
icon_id
1694-
)
1695-
VALUES(?, ?, ?, ?, ?, ?, ?, ?)
1696-
",
1697-
)?))
1698-
}
1699-
1700-
fn execute(
1701-
&mut self,
1702-
suggestion_id: i64,
1703-
fakespot: &DownloadedFakespotSuggestion,
1704-
) -> Result<()> {
1705-
let icon_id = fakespot
1706-
.product_id
1707-
.split_once('-')
1708-
.map(|(vendor, _)| format!("fakespot-{vendor}"));
1709-
self.0
1710-
.execute((
1711-
suggestion_id,
1712-
&fakespot.fakespot_grade,
1713-
&fakespot.product_id,
1714-
&fakespot.keywords.to_lowercase(),
1715-
&fakespot.product_type.to_lowercase(),
1716-
fakespot.rating,
1717-
fakespot.total_reviews,
1718-
icon_id,
1719-
))
1720-
.with_context("fakespot insert")?;
1721-
Ok(())
1722-
}
1723-
}
1724-
17251543
struct DynamicInsertStatement<'conn>(rusqlite::Statement<'conn>);
17261544

17271545
impl<'conn> DynamicInsertStatement<'conn> {

0 commit comments

Comments
 (0)