Fix redundant method chains

This commit is contained in:
Kitaiti Makoto 2021-01-15 23:17:00 +09:00
parent 4cdc1a3655
commit 0775c8f3f9
3 changed files with 14 additions and 19 deletions

View File

@ -303,9 +303,7 @@ fn get_proxy_config() -> Option<ProxyConfig> {
if only_domains.contains(domain) if only_domains.contains(domain)
|| only_domains || only_domains
.iter() .iter()
.filter(|target| domain.ends_with(&format!(".{}", target))) .any(|target| domain.ends_with(&format!(".{}", target)))
.next()
.is_some()
{ {
Some(proxy_url.clone()) Some(proxy_url.clone())
} else { } else {
@ -317,7 +315,6 @@ fn get_proxy_config() -> Option<ProxyConfig> {
}) })
} else { } else {
reqwest::Proxy::all(proxy_url) reqwest::Proxy::all(proxy_url)
.ok()
.expect("Invalid PROXY_URL") .expect("Invalid PROXY_URL")
}; };
Some(ProxyConfig { Some(ProxyConfig {

View File

@ -123,8 +123,7 @@ impl Post {
.filter(posts::published.eq(true)) .filter(posts::published.eq(true))
.count() .count()
.load(conn)? .load(conn)?
.iter() .get(0)
.next()
.cloned() .cloned()
.ok_or(Error::NotFound) .ok_or(Error::NotFound)
} }
@ -287,17 +286,16 @@ impl Post {
} }
pub fn get_receivers_urls(&self, conn: &Connection) -> Result<Vec<String>> { pub fn get_receivers_urls(&self, conn: &Connection) -> Result<Vec<String>> {
let followers = self Ok(self
.get_authors(conn)? .get_authors(conn)?
.into_iter() .into_iter()
.filter_map(|a| a.get_followers(conn).ok()) .filter_map(|a| a.get_followers(conn).ok())
.collect::<Vec<Vec<User>>>(); .fold(vec![], |mut acc, f| {
Ok(followers.into_iter().fold(vec![], |mut acc, f| { for x in f {
for x in f { acc.push(x.ap_url);
acc.push(x.ap_url); }
} acc
acc }))
}))
} }
pub fn to_activity(&self, conn: &Connection) -> Result<LicensedArticle> { pub fn to_activity(&self, conn: &Connection) -> Result<LicensedArticle> {

View File

@ -45,7 +45,7 @@ pub fn upload(
let (_, boundary) = ct let (_, boundary) = ct
.params() .params()
.find(|&(k, _)| k == "boundary") .find(|&(k, _)| k == "boundary")
.ok_or_else(|| status::BadRequest(Some("No boundary")))?; .ok_or(status::BadRequest(Some("No boundary")))?;
if let SaveResult::Full(entries) = Multipart::with_body(data.open(), boundary).save().temp() { if let SaveResult::Full(entries) = Multipart::with_body(data.open(), boundary).save().temp() {
let fields = entries.fields; let fields = entries.fields;
@ -53,7 +53,7 @@ pub fn upload(
let filename = fields let filename = fields
.get("file") .get("file")
.and_then(|v| v.iter().next()) .and_then(|v| v.iter().next())
.ok_or_else(|| status::BadRequest(Some("No file uploaded")))? .ok_or(status::BadRequest(Some("No file uploaded")))?
.headers .headers
.filename .filename
.clone(); .clone();