Skip to content

Commit e2f5a81

Browse files
committed
address review feedback
1 parent cac826d commit e2f5a81

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/bin/server/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ impl Worker {
349349
// time elapsed since the last save.
350350
match self.last_index_backup {
351351
Some(last) if last.elapsed() >= MINIMUM_DELAY_BETWEEN_INDEX_BACKUPS => {
352-
self.index.save(&self.index_file)?;
353352
self.last_index_backup = Some(Instant::now());
353+
self.index.save(&self.index_file)?;
354354
}
355355
Some(_) => {}
356356
None => self.last_index_backup = Some(Instant::now()),

src/index/storage.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use aws_sdk_s3::config::Region;
55
use aws_sdk_s3::error::SdkError;
66
use aws_sdk_s3::operation::get_object::GetObjectError;
77
use aws_sdk_s3::Client as S3Client;
8+
use hyper::body::Buf;
89
use std::fs::File;
9-
use std::io::Cursor;
1010
use std::path::PathBuf;
1111
use std::str::FromStr;
1212
use std::sync::Arc;
@@ -143,13 +143,9 @@ impl S3Storage {
143143
.await;
144144

145145
match result {
146-
Ok(response) => {
147-
// FIXME: this buffers the downloaded data into memory before deserializing it,
148-
// as I'm not aware of a way to convert from AsyncRead to Read.
149-
let mut buf = Vec::new();
150-
tokio::io::copy(&mut response.body.into_async_read(), &mut buf).await?;
151-
Ok(Some(Index::deserialize(&mut Cursor::new(buf))?))
152-
}
146+
Ok(response) => Ok(Some(Index::deserialize(
147+
&mut response.body.collect().await?.reader(),
148+
)?)),
153149
Err(err) => {
154150
if let SdkError::ServiceError(service_err) = &err {
155151
if let GetObjectError::NoSuchKey(_) = service_err.err() {
@@ -167,7 +163,7 @@ impl S3Storage {
167163
// FIXME: this buffers the serialized data into memory before sending it, as I'm not
168164
// aware of a way to convert from Write to AsyncWrite.
169165
let mut buf = Vec::new();
170-
index.serialize(&mut Cursor::new(&mut buf))?;
166+
index.serialize(&mut buf)?;
171167

172168
self.client
173169
.put_object()

0 commit comments

Comments
 (0)