refactor: remove some clones and follow clippy
This commit is contained in:
parent
d971927b4d
commit
22c2387eb2
1 changed files with 13 additions and 18 deletions
31
src/main.rs
31
src/main.rs
|
|
@ -16,40 +16,35 @@ async fn get_feed(url: String, client: &Client) -> Result<Channel> {
|
|||
}
|
||||
|
||||
fn get_domain(item: &rss::Item) -> Option<String> {
|
||||
item.link().map(|link| {
|
||||
Url::parse(link)
|
||||
.ok()
|
||||
.map(|parsed| parsed.domain().map(|domain| domain.to_string()))
|
||||
}).flatten()?
|
||||
item.link()
|
||||
.and_then(|link| Url::parse(link).ok())
|
||||
.and_then(|parsed| parsed.domain().map(|domain| domain.to_string()))
|
||||
}
|
||||
|
||||
async fn complete(channel: Channel, client: &Client) -> Result<Box<Channel>> {
|
||||
let grouped: Vec<Vec<rss::Item>> = channel
|
||||
.items()
|
||||
.into_iter()
|
||||
.chunk_by(|item| get_domain(*item))
|
||||
.iter()
|
||||
.chunk_by(|item| get_domain(item))
|
||||
.into_iter()
|
||||
.map(|(_k, v)| v.cloned().collect())
|
||||
.collect();
|
||||
|
||||
let mut set = JoinSet::new();
|
||||
for items in grouped.into_iter() {
|
||||
for mut items in grouped.into_iter() {
|
||||
let client = client.clone();
|
||||
set.spawn(async move {
|
||||
let mut new_items = vec![];
|
||||
let mut wait_time = Duration::from_secs(0);
|
||||
for item in items {
|
||||
for item in &mut items {
|
||||
tokio::time::sleep(wait_time).await;
|
||||
let mut new_item: rss::Item = item.clone().to_owned();
|
||||
if let Some(link) = item.link() {
|
||||
if let Ok(content) = get_content(link, &client.clone()).await {
|
||||
new_item.set_description(content);
|
||||
};
|
||||
};
|
||||
new_items.push(new_item);
|
||||
if let Some(ref link) = item.link
|
||||
&& let Ok(content) = get_content(link, &client.clone()).await
|
||||
{
|
||||
item.set_description(content);
|
||||
}
|
||||
wait_time = Duration::from_secs(1);
|
||||
}
|
||||
new_items
|
||||
items
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue