Skip to content

Commit

Permalink
refactor: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mickvandijke committed May 4, 2023
1 parent 005817f commit d5c5487
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub async fn run(configuration: Configuration) -> Running {
auth.clone(),
tracker_service.clone(),
mailer_service,
image_cache_service
image_cache_service,
));

// Start repeating task to import tracker torrent data and updating
Expand Down
8 changes: 4 additions & 4 deletions src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ mod tests {
}

#[tokio::test]
async fn given_a_bytes_cache_with_a_capacity_and_entry_size_limit_it_should_allow_adding_new_entries_if_the_limit_is_not_exceeded() {

async fn given_a_bytes_cache_with_a_capacity_and_entry_size_limit_it_should_allow_adding_new_entries_if_the_limit_is_not_exceeded(
) {
let bytes: Bytes = Bytes::from("abcdef");

let mut bytes_cache = BytesCache::with_capacity_and_entry_size_limit(bytes.len() * 2, bytes.len()).unwrap();
Expand All @@ -171,8 +171,8 @@ mod tests {
}

#[tokio::test]
async fn given_a_bytes_cache_with_a_capacity_and_entry_size_limit_it_should_not_allow_adding_new_entries_if_the_capacity_is_exceeded() {

async fn given_a_bytes_cache_with_a_capacity_and_entry_size_limit_it_should_not_allow_adding_new_entries_if_the_capacity_is_exceeded(
) {
let bytes: Bytes = Bytes::from("abcdef");

let mut bytes_cache = BytesCache::with_capacity_and_entry_size_limit(bytes.len() * 2 - 1, bytes.len()).unwrap();
Expand Down
19 changes: 15 additions & 4 deletions src/cache/image/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ impl ImageCacheService {
}

async fn get_image_from_url_as_bytes(&self, url: &str) -> Result<Bytes, Error> {
let res = self.reqwest_client.clone()
let res = self
.reqwest_client
.clone()
.get(url)
.send()
.await
Expand Down Expand Up @@ -171,7 +173,14 @@ impl ImageCacheService {
}

async fn update_image_cache(&self, url: &str, image_bytes: &Bytes) -> Result<(), Error> {
if self.image_cache.write().await.set(url.to_string(), image_bytes.clone()).await.is_err() {
if self
.image_cache
.write()
.await
.set(url.to_string(), image_bytes.clone())
.await
.is_err()
{
return Err(Error::ImageTooBig);
}

Expand All @@ -181,7 +190,10 @@ impl ImageCacheService {
async fn update_user_quota(&self, user: &UserCompact, amount: usize) -> Result<(), Error> {
let settings = self.cfg.settings.read().await;

let mut quota = self.user_quotas.read().await
let mut quota = self
.user_quotas
.read()
.await
.get(&user.user_id)
.cloned()
.unwrap_or(ImageCacheQuota::new(
Expand All @@ -196,5 +208,4 @@ impl ImageCacheService {

Ok(())
}

}
9 changes: 4 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct ImageCache {
pub capacity: usize,
pub entry_size_limit: usize,
pub user_quota_period_seconds: u64,
pub user_quota_bytes: usize
pub user_quota_bytes: usize,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -87,7 +87,7 @@ pub struct TorrustConfig {
pub auth: Auth,
pub database: Database,
pub mail: Mail,
pub image_cache: ImageCache
pub image_cache: ImageCache,
}

impl TorrustConfig {
Expand Down Expand Up @@ -131,13 +131,12 @@ impl TorrustConfig {
capacity: 128_000_000,
entry_size_limit: 4_000_000,
user_quota_period_seconds: 3600,
user_quota_bytes: 64_000_000
}
user_quota_bytes: 64_000_000,
},
}
}
}


#[derive(Debug)]
pub struct Configuration {
pub settings: RwLock<TorrustConfig>,
Expand Down

0 comments on commit d5c5487

Please sign in to comment.