From f726a42f6190ee3f0438a83823b89fa038eb8301 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 21 Feb 2022 20:51:00 +0300 Subject: database: code cleanup --- src/database/file/mod.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/database/file') diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs index da8a06a..d1227d8 100644 --- a/src/database/file/mod.rs +++ b/src/database/file/mod.rs @@ -196,7 +196,7 @@ fn modify_post(post: &serde_json::Value, update: &serde_json::Value) -> Result { @@ -291,7 +292,7 @@ impl Storage for FileStorage { })).await?.unwrap() } - async fn put_post<'a>(&self, post: &'a serde_json::Value, user: &'a str) -> Result<()> { + async fn put_post(&self, post: &'_ serde_json::Value, user: &'_ str) -> Result<()> { let key = post["properties"]["uid"][0] .as_str() .expect("Tried to save a post without UID"); @@ -384,6 +385,7 @@ impl Storage for FileStorage { .map(|s| s.to_string()) .unwrap_or_else(String::default); let key = key.to_string(); + #[allow(clippy::drop_ref)] // using drop() to prevent mistakes here drop(post); tokio::time::timeout(Duration::from_secs(IO_TIMEOUT), spawn_blocking(move || { let file = OpenOptions::new() @@ -421,7 +423,7 @@ impl Storage for FileStorage { Ok(()) } - async fn update_post<'a>(&self, url: &'a str, update: serde_json::Value) -> Result<()> { + async fn update_post(&self, url: &'_ str, update: serde_json::Value) -> Result<()> { let path = url_to_path(&self.root_dir, url); #[allow(unused_variables)] let (old_json, new_json) = tokio::time::timeout( @@ -454,7 +456,7 @@ impl Storage for FileStorage { Ok(()) } - async fn get_channels<'a>(&self, user: &'a str) -> Result> { + async fn get_channels(&self, user: &'_ str) -> Result> { let mut path = relative_path::RelativePathBuf::new(); path.push(warp::http::Uri::try_from(user.to_string()).unwrap().authority().unwrap().to_string()); path.push("channels"); @@ -486,12 +488,12 @@ impl Storage for FileStorage { })).await?.unwrap() } - async fn read_feed_with_limit<'a>( + async fn read_feed_with_limit( &self, - url: &'a str, - after: &'a Option, + url: &'_ str, + after: &'_ Option, limit: usize, - user: &'a Option, + user: &'_ Option, ) -> Result> { if let Some(feed) = self.get_post(url).await? { if let Some(mut feed) = filter_post(feed, user) { @@ -545,7 +547,7 @@ impl Storage for FileStorage { } } - async fn delete_post<'a>(&self, url: &'a str) -> Result<()> { + async fn delete_post(&self, url: &'_ str) -> Result<()> { let path = url_to_path(&self.root_dir, url); if let Err(e) = tokio::fs::remove_file(path).await { Err(e.into()) @@ -555,7 +557,7 @@ impl Storage for FileStorage { } } - async fn get_setting<'a>(&self, setting: &'a str, user: &'a str) -> Result { + async fn get_setting(&self, setting: &'_ str, user: &'_ str) -> Result { log::debug!("User for getting settings: {}", user); let url = http_types::Url::parse(user).expect("Couldn't parse a URL"); let mut path = relative_path::RelativePathBuf::new(); @@ -581,7 +583,7 @@ impl Storage for FileStorage { })).await?.unwrap() } - async fn set_setting<'a>(&self, setting: &'a str, user: &'a str, value: &'a str) -> Result<()> { + async fn set_setting(&self, setting: &'_ str, user: &'_ str, value: &'_ str) -> Result<()> { let url = http_types::Url::parse(user).expect("Couldn't parse a URL"); let mut path = relative_path::RelativePathBuf::new(); path.push(url.origin().ascii_serialization()); @@ -618,7 +620,7 @@ impl Storage for FileStorage { settings.insert(setting.to_string(), value.to_string()); (&mut *guard).seek(SeekFrom::Start(0))?; - (&mut *guard).set_len(0)?; + (*guard).set_len(0)?; (&mut *guard).write_all(serde_json::to_string(&settings)?.as_bytes())?; Result::Ok(()) })).await?.unwrap() -- cgit 1.4.1