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> {
|
fn get_domain(item: &rss::Item) -> Option<String> {
|
||||||
item.link().map(|link| {
|
item.link()
|
||||||
Url::parse(link)
|
.and_then(|link| Url::parse(link).ok())
|
||||||
.ok()
|
.and_then(|parsed| parsed.domain().map(|domain| domain.to_string()))
|
||||||
.map(|parsed| parsed.domain().map(|domain| domain.to_string()))
|
|
||||||
}).flatten()?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn complete(channel: Channel, client: &Client) -> Result<Box<Channel>> {
|
async fn complete(channel: Channel, client: &Client) -> Result<Box<Channel>> {
|
||||||
let grouped: Vec<Vec<rss::Item>> = channel
|
let grouped: Vec<Vec<rss::Item>> = channel
|
||||||
.items()
|
.items()
|
||||||
.into_iter()
|
.iter()
|
||||||
.chunk_by(|item| get_domain(*item))
|
.chunk_by(|item| get_domain(item))
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_k, v)| v.cloned().collect())
|
.map(|(_k, v)| v.cloned().collect())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut set = JoinSet::new();
|
let mut set = JoinSet::new();
|
||||||
for items in grouped.into_iter() {
|
for mut items in grouped.into_iter() {
|
||||||
let client = client.clone();
|
let client = client.clone();
|
||||||
set.spawn(async move {
|
set.spawn(async move {
|
||||||
let mut new_items = vec![];
|
|
||||||
let mut wait_time = Duration::from_secs(0);
|
let mut wait_time = Duration::from_secs(0);
|
||||||
for item in items {
|
for item in &mut items {
|
||||||
tokio::time::sleep(wait_time).await;
|
tokio::time::sleep(wait_time).await;
|
||||||
let mut new_item: rss::Item = item.clone().to_owned();
|
if let Some(ref link) = item.link
|
||||||
if let Some(link) = item.link() {
|
&& let Ok(content) = get_content(link, &client.clone()).await
|
||||||
if let Ok(content) = get_content(link, &client.clone()).await {
|
{
|
||||||
new_item.set_description(content);
|
item.set_description(content);
|
||||||
};
|
}
|
||||||
};
|
|
||||||
new_items.push(new_item);
|
|
||||||
wait_time = Duration::from_secs(1);
|
wait_time = Duration::from_secs(1);
|
||||||
}
|
}
|
||||||
new_items
|
items
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue