Skip to content

Commit

Permalink
cloneable request expect vecs
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-prosser committed Jul 25, 2024
1 parent 617ade7 commit ca6d538
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
30 changes: 10 additions & 20 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,13 @@ impl Client {
pub fn put_comments(
&self,
source_name: &SourceFullName,
comments: &[NewComment],
comments: Vec<NewComment>,
no_charge: bool,
) -> Result<PutCommentsResponse> {
self.request(
Method::PUT,
self.endpoints.put_comments(source_name)?,
Some(PutCommentsRequest {
comments: comments.to_vec(),
}),
Some(PutCommentsRequest { comments }),
Some(NoChargeQuery { no_charge }),
Retry::No,
)
Expand Down Expand Up @@ -580,15 +578,13 @@ impl Client {
pub fn sync_comments(
&self,
source_name: &SourceFullName,
comments: &[NewComment],
comments: Vec<NewComment>,
no_charge: bool,
) -> Result<SyncCommentsResponse> {
self.request(
Method::POST,
self.endpoints.sync_comments(source_name)?,
Some(SyncCommentsRequest {
comments: comments.to_vec(),
}),
Some(SyncCommentsRequest { comments }),
Some(NoChargeQuery { no_charge }),
Retry::Yes,
)
Expand All @@ -597,15 +593,13 @@ impl Client {
pub fn sync_comments_split_on_failure(
&self,
source_name: &SourceFullName,
comments: &[NewComment],
comments: Vec<NewComment>,
no_charge: bool,
) -> Result<SplitableRequestResponse<SyncCommentsResponse>> {
self.splitable_request(
Method::POST,
self.endpoints.sync_comments(source_name)?,
SyncCommentsRequest {
comments: comments.to_vec(),
},
SyncCommentsRequest { comments },
Some(NoChargeQuery { no_charge }),
Retry::Yes,
)
Expand Down Expand Up @@ -635,15 +629,13 @@ impl Client {
pub fn put_emails_split_on_failure(
&self,
bucket_name: &BucketFullName,
emails: &[NewEmail],
emails: Vec<NewEmail>,
no_charge: bool,
) -> Result<SplitableRequestResponse<PutEmailsResponse>> {
self.splitable_request(
Method::PUT,
self.endpoints.put_emails(bucket_name)?,
PutEmailsRequest {
emails: emails.to_vec(),
},
PutEmailsRequest { emails },
Some(NoChargeQuery { no_charge }),
Retry::Yes,
)
Expand All @@ -652,15 +644,13 @@ impl Client {
pub fn put_emails(
&self,
bucket_name: &BucketFullName,
emails: &[NewEmail],
emails: Vec<NewEmail>,
no_charge: bool,
) -> Result<PutEmailsResponse> {
self.request(
Method::PUT,
self.endpoints.put_emails(bucket_name)?,
Some(PutEmailsRequest {
emails: emails.to_vec(),
}),
Some(PutEmailsRequest { emails }),
Some(NoChargeQuery { no_charge }),
Retry::Yes,
)
Expand Down
10 changes: 7 additions & 3 deletions cli/src/commands/create/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ fn upload_batch_of_comments(
failed += result.num_failed;
} else {
client
.put_comments(&source.full_name(), comments_to_put, no_charge)
.put_comments(&source.full_name(), comments_to_put.to_vec(), no_charge)
.context("Could not put batch of comments")?;
}
uploaded += comments_to_put.len() - failed;
Expand All @@ -303,13 +303,17 @@ fn upload_batch_of_comments(
if !comments_to_sync.is_empty() {
let result = if resume_on_error {
let result = client
.sync_comments_split_on_failure(&source.full_name(), comments_to_sync, no_charge)
.sync_comments_split_on_failure(
&source.full_name(),
comments_to_sync.to_vec(),
no_charge,
)
.context("Could not sync batch of comments")?;
failed += result.num_failed;
result.response
} else {
client
.sync_comments(&source.full_name(), comments_to_sync, no_charge)
.sync_comments(&source.full_name(), comments_to_sync.to_vec(), no_charge)
.context("Could not sync batch of comments")?
};

Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/create/emails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn upload_emails_from_reader(

if resume_on_error {
let result = client
.put_emails_split_on_failure(&bucket.full_name(), &batch, no_charge)
.put_emails_split_on_failure(&bucket.full_name(), batch.to_vec(), no_charge)
.context("Could not upload batch of emails")?;
statistics.add_emails(StatisticsUpdate {
uploaded: batch.len() - result.num_failed,
Expand All @@ -169,7 +169,7 @@ fn upload_emails_from_reader(
batch.clear();
} else {
client
.put_emails(&bucket.full_name(), &batch, no_charge)
.put_emails(&bucket.full_name(), batch.to_vec(), no_charge)
.context("Could not upload batch of emails")?;
statistics.add_emails(StatisticsUpdate {
uploaded: batch.len(),
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn upload_batch_of_new_emails(
no_charge: bool,
statistics: &Arc<Statistics>,
) -> Result<()> {
client.put_emails(bucket, emails, no_charge)?;
client.put_emails(bucket, emails.to_vec(), no_charge)?;
statistics.add_uploaded(emails.len());
Ok(())
}
Expand Down

0 comments on commit ca6d538

Please sign in to comment.