Skip to content

Commit

Permalink
rebase changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiftran committed Feb 26, 2025
1 parent be662ea commit 5ddb547
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion components/suggest/src/benchmarks/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl rs::Client for RemoteSettingsBenchmarkClient {
.collect())
}

fn download_attachment(&self, record: &rs::Record) -> Result<Vec<u8>> {
fn download_attachment(&self, record: rs::Record) -> Result<Vec<u8>> {
match &record.attachment {
Some(a) => match self.attachments.get(&a.location) {
Some(data) => Ok(data.clone()),
Expand Down
6 changes: 4 additions & 2 deletions components/suggest/src/benchmarks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
14 changes: 7 additions & 7 deletions components/suggest/src/rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Record>>;

fn download_attachment(&self, record: &Record) -> Result<Vec<u8>>;
fn download_attachment(&self, record: Record) -> Result<Vec<u8>>;
}

/// Implements the [Client] trait using a real remote settings client
Expand All @@ -85,11 +85,10 @@ pub struct SuggestRemoteSettingsClient {
}

impl SuggestRemoteSettingsClient {
pub fn new(rs_service: &RemoteSettingsService, ) -> Result<Self> {
pub fn new(rs_service: &RemoteSettingsService) -> Result<Self> {
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())?,
})
}

Expand Down Expand Up @@ -119,11 +118,12 @@ impl Client for SuggestRemoteSettingsClient {
}
}

fn download_attachment(&self, record: &Record) -> Result<Vec<u8>> {
fn download_attachment(&self, record: Record) -> Result<Vec<u8>> {
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())),
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ impl From<Record> 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(),
}
}
Expand Down
9 changes: 5 additions & 4 deletions components/suggest/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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::<SuggestAttachment<T>>(&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
Expand Down
2 changes: 1 addition & 1 deletion components/suggest/src/testing/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl Client for MockRemoteSettingsClient {
.collect())
}

fn download_attachment(&self, record: &Record) -> Result<Vec<u8>> {
fn download_attachment(&self, record: Record) -> Result<Vec<u8>> {
match &record.attachment {
None => Err(Error::MissingAttachment(record.id.to_string())),
Some(a) => Ok(self
Expand Down

0 comments on commit 5ddb547

Please sign in to comment.