Converted iter_mut into into_iter wherever possible.

This commit is contained in:
Jordan Petridis 2017-11-18 19:23:25 +02:00
parent 494761beaf
commit 5c84b77434
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 17 additions and 16 deletions

View File

@ -48,15 +48,16 @@ impl Feed {
// The synchronous version where there was a db.lock() before the episodes.iter() // The synchronous version where there was a db.lock() before the episodes.iter()
// is actually faster. // is actually faster.
fn index_channel_items(&self, db: &Database, pd: &Podcast) -> Result<()> { fn index_channel_items(&self, db: &Database, pd: &Podcast) -> Result<()> {
let it = self.channel.items(); let items = self.channel.items();
let episodes: Vec<_> = it.par_iter() let episodes: Vec<_> = items
.map(|x| parser::new_episode(x, *pd.id())) .into_par_iter()
.map(|item| parser::new_episode(item, *pd.id()))
.collect(); .collect();
episodes.into_par_iter().for_each(|x| { episodes.into_par_iter().for_each(|ep| {
let e = x.index(&Arc::clone(db)); let e = ep.index(&Arc::clone(db));
if let Err(err) = e { if let Err(err) = e {
error!("Failed to index episode: {:?}.", x); error!("Failed to index episode: {:?}.", ep);
error!("Error msg: {}", err); error!("Error msg: {}", err);
}; };
}); });
@ -72,9 +73,9 @@ pub fn index_all(db: &Database) -> Result<()> {
Ok(()) Ok(())
} }
pub fn index(db: &Database, f: &mut [Feed]) { pub fn index(db: &Database, feeds: &mut [Feed]) {
f.into_par_iter().for_each(|x| { feeds.into_par_iter().for_each(|f| {
let e = x.index(&Arc::clone(db)); let e = f.index(&Arc::clone(db));
if e.is_err() { if e.is_err() {
error!("Error While trying to update the database."); error!("Error While trying to update the database.");
error!("Error msg: {}", e.unwrap_err()); error!("Error msg: {}", e.unwrap_err());

View File

@ -12,12 +12,12 @@ use std::sync::Arc;
// TODO: Write unit test. // TODO: Write unit test.
fn download_checker(db: &Database) -> Result<()> { fn download_checker(db: &Database) -> Result<()> {
let mut episodes = { let episodes = {
let tempdb = db.lock().unwrap(); let tempdb = db.lock().unwrap();
dbqueries::get_downloaded_episodes(&tempdb)? dbqueries::get_downloaded_episodes(&tempdb)?
}; };
episodes.par_iter_mut().for_each(|ep| { episodes.into_par_iter().for_each(|mut ep| {
if !Path::new(ep.local_uri().unwrap()).exists() { if !Path::new(ep.local_uri().unwrap()).exists() {
ep.set_local_uri(None); ep.set_local_uri(None);
let res = ep.save(&Arc::clone(db)); let res = ep.save(&Arc::clone(db));
@ -33,13 +33,13 @@ fn download_checker(db: &Database) -> Result<()> {
// TODO: Write unit test. // TODO: Write unit test.
fn played_cleaner(db: &Database) -> Result<()> { fn played_cleaner(db: &Database) -> Result<()> {
let mut episodes = { let episodes = {
let tempdb = db.lock().unwrap(); let tempdb = db.lock().unwrap();
dbqueries::get_played_episodes(&tempdb)? dbqueries::get_played_episodes(&tempdb)?
}; };
let now_utc = Utc::now().timestamp() as i32; let now_utc = Utc::now().timestamp() as i32;
episodes.par_iter_mut().for_each(|mut ep| { episodes.into_par_iter().for_each(|mut ep| {
if ep.local_uri().is_some() && ep.played().is_some() { if ep.local_uri().is_some() && ep.played().is_some() {
let played = ep.played().unwrap(); let played = ep.played().unwrap();
// TODO: expose a config and a user set option. // TODO: expose a config and a user set option.

View File

@ -202,12 +202,12 @@ fn receive() -> glib::Continue {
pub fn episodes_listbox(db: &Database, pd: &Podcast) -> Result<gtk::ListBox> { pub fn episodes_listbox(db: &Database, pd: &Podcast) -> Result<gtk::ListBox> {
let conn = db.lock().unwrap(); let conn = db.lock().unwrap();
let mut episodes = dbqueries::get_pd_episodes(&conn, pd)?; let episodes = dbqueries::get_pd_episodes(&conn, pd)?;
drop(conn); drop(conn);
let list = gtk::ListBox::new(); let list = gtk::ListBox::new();
episodes.iter_mut().for_each(|ep| { episodes.into_iter().for_each(|mut ep| {
let w = epidose_widget(db, ep, pd.title()); let w = epidose_widget(db, &mut ep, pd.title());
list.add(&w) list.add(&w)
}); });