diff --git a/components/suggest/src/benchmarks/client.rs b/components/suggest/src/benchmarks/client.rs index 8b52a6a227..d2b6ca8a79 100644 --- a/components/suggest/src/benchmarks/client.rs +++ b/components/suggest/src/benchmarks/client.rs @@ -96,7 +96,7 @@ impl rs::Client for RemoteSettingsBenchmarkClient { .collect()) } - fn download_attachment(&self, record: &rs::Record) -> Result> { + fn download_attachment(&self, record: rs::Record) -> Result> { match &record.attachment { Some(a) => match self.attachments.get(&a.location) { Some(data) => Ok(data.clone()), diff --git a/components/suggest/src/benchmarks/mod.rs b/components/suggest/src/benchmarks/mod.rs index be2cfe3792..70183ce533 100644 --- a/components/suggest/src/benchmarks/mod.rs +++ b/components/suggest/src/benchmarks/mod.rs @@ -20,8 +20,8 @@ use std::{ use tempfile::TempDir; use crate::{SuggestIngestionConstraints, SuggestStore}; -use remote_settings::RemoteSettingsConfig2; -use remote_settings::RemoteSettingsService; +use remote_settings::{RemoteSettingsConfig2, RemoteSettingsContext, RemoteSettingsService}; + use std::sync::Arc; pub mod client; @@ -82,6 +82,7 @@ fn new_store() -> SuggestStore { let rs_config = RemoteSettingsConfig2 { bucket_name: None, server: None, + app_context: Some(RemoteSettingsContext::default()), }; let remote_settings_service = Arc::new(RemoteSettingsService::new("".to_string(), rs_config).unwrap()); @@ -98,6 +99,7 @@ fn new_store() -> SuggestStore { let rs_config = RemoteSettingsConfig2 { bucket_name: None, server: None, + app_context: Some(RemoteSettingsContext::default()), }; let remote_settings_service = Arc::new(RemoteSettingsService::new("".to_string(), rs_config).unwrap()); diff --git a/components/suggest/src/rs.rs b/components/suggest/src/rs.rs index d06552345d..fa45d84365 100644 --- a/components/suggest/src/rs.rs +++ b/components/suggest/src/rs.rs @@ -74,7 +74,7 @@ pub(crate) trait Client { /// Records that can't be parsed as [SuggestRecord] are ignored. fn get_records(&self, collection: Collection) -> Result>; - fn download_attachment(&self, record: &Record) -> Result>; + fn download_attachment(&self, record: Record) -> Result>; } /// Implements the [Client] trait using a real remote settings client @@ -85,11 +85,10 @@ pub struct SuggestRemoteSettingsClient { } impl SuggestRemoteSettingsClient { - pub fn new(rs_service: &RemoteSettingsService, ) -> Result { + pub fn new(rs_service: &RemoteSettingsService) -> Result { Ok(Self { quicksuggest_client: rs_service.make_client("quicksuggest".to_owned())?, - fakespot_client: rs_service - .make_client("fakespot-suggest-products".to_owned())?, + fakespot_client: rs_service.make_client("fakespot-suggest-products".to_owned())?, }) } @@ -119,11 +118,12 @@ impl Client for SuggestRemoteSettingsClient { } } - fn download_attachment(&self, record: &Record) -> Result> { + fn download_attachment(&self, record: Record) -> Result> { + let converted_record: RemoteSettingsRecord = record.clone().into(); match &record.attachment { Some(_a) => Ok(self .client_for_collection(record.collection) - .get_attachment(record.clone().into())?), + .get_attachment(&converted_record)?), None => Err(Error::MissingAttachment(record.id.to_string())), } } @@ -163,7 +163,7 @@ impl From for RemoteSettingsRecord { id: record.id.to_string(), last_modified: record.last_modified, deleted: false, - attachment: record.attachment, + attachment: record.attachment.clone(), fields: record.payload.to_json_map(), } } diff --git a/components/suggest/src/store.rs b/components/suggest/src/store.rs index 87dde6aa3b..e3fdab6ff4 100644 --- a/components/suggest/src/store.rs +++ b/components/suggest/src/store.rs @@ -661,8 +661,9 @@ where // malformed, so skip to the next record. return Ok(()); }; - let data = context - .measure_download(|| self.settings_client.download_attachment(record))?; + let data = context.measure_download(|| { + self.settings_client.download_attachment(record.clone()) + })?; dao.put_icon(icon_id, &data, &attachment.mimetype)?; } SuggestRecord::Amo => { @@ -732,8 +733,8 @@ where return Ok(()); }; - let attachment_data = - context.measure_download(|| self.settings_client.download_attachment(record))?; + let attachment_data = context + .measure_download(|| self.settings_client.download_attachment(record.clone()))?; match serde_json::from_slice::>(&attachment_data) { Ok(attachment) => ingestion_handler(dao, &record.id, attachment.suggestions()), // If the attachment doesn't match our expected schema, just skip it. It's possible diff --git a/components/suggest/src/testing/client.rs b/components/suggest/src/testing/client.rs index 7124eb070e..6dc37a98af 100644 --- a/components/suggest/src/testing/client.rs +++ b/components/suggest/src/testing/client.rs @@ -272,7 +272,7 @@ impl Client for MockRemoteSettingsClient { .collect()) } - fn download_attachment(&self, record: &Record) -> Result> { + fn download_attachment(&self, record: Record) -> Result> { match &record.attachment { None => Err(Error::MissingAttachment(record.id.to_string())), Some(a) => Ok(self diff --git a/examples/suggest-cli/src/main.rs b/examples/suggest-cli/src/main.rs index 8bc19fa3c4..fb6d6a691d 100644 --- a/examples/suggest-cli/src/main.rs +++ b/examples/suggest-cli/src/main.rs @@ -7,7 +7,9 @@ use std::{collections::HashMap, sync::Arc}; use anyhow::Result; use clap::{Parser, Subcommand, ValueEnum}; -use remote_settings::{RemoteSettingsConfig2, RemoteSettingsServer, RemoteSettingsService}; +use remote_settings::{ + RemoteSettingsConfig2, RemoteSettingsContext, RemoteSettingsServer, RemoteSettingsService, +}; use suggest::{ AmpMatchingStrategy, SuggestIngestionConstraints, SuggestStore, SuggestStoreBuilder, SuggestionProvider, SuggestionProviderConstraints, SuggestionQuery, @@ -150,6 +152,7 @@ fn build_store(cli: &Cli) -> Arc { RemoteSettingsConfig2 { server: None, bucket_name: None, + app_context: Some(RemoteSettingsContext::default()), }, ) .unwrap();