Reverted index_channel items to the synchronous version.
Using a transaction yields ~1/3 better performance as of now.
This commit is contained in:
parent
5c84b77434
commit
563f249a48
@ -1,5 +1,6 @@
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use diesel::Identifiable;
|
use diesel::Identifiable;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
|
||||||
use rss;
|
use rss;
|
||||||
|
|
||||||
@ -44,9 +45,7 @@ impl Feed {
|
|||||||
pd.into_podcast(db)
|
pd.into_podcast(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Figure out transcactions.
|
// TODO: Refactor transcactions and find a way to do it in parallel.
|
||||||
// The synchronous version where there was a db.lock() before the episodes.iter()
|
|
||||||
// is actually faster.
|
|
||||||
fn index_channel_items(&self, db: &Database, pd: &Podcast) -> Result<()> {
|
fn index_channel_items(&self, db: &Database, pd: &Podcast) -> Result<()> {
|
||||||
let items = self.channel.items();
|
let items = self.channel.items();
|
||||||
let episodes: Vec<_> = items
|
let episodes: Vec<_> = items
|
||||||
@ -54,14 +53,18 @@ impl Feed {
|
|||||||
.map(|item| parser::new_episode(item, *pd.id()))
|
.map(|item| parser::new_episode(item, *pd.id()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
episodes.into_par_iter().for_each(|ep| {
|
let tempdb = db.lock().unwrap();
|
||||||
let e = ep.index(&Arc::clone(db));
|
let _ = tempdb.transaction::<(), Error, _>(|| {
|
||||||
|
episodes.into_iter().for_each(|x| {
|
||||||
|
let e = x.index(&tempdb);
|
||||||
if let Err(err) = e {
|
if let Err(err) = e {
|
||||||
error!("Failed to index episode: {:?}.", ep);
|
error!("Failed to index episode: {:?}.", x);
|
||||||
error!("Error msg: {}", err);
|
error!("Error msg: {}", err);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
|
});
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -62,26 +62,29 @@ impl<'a> NewEpisode<'a> {
|
|||||||
// TODO: Currently using diesel from master git.
|
// TODO: Currently using diesel from master git.
|
||||||
// Watch out for v0.99.0 beta and change the toml.
|
// Watch out for v0.99.0 beta and change the toml.
|
||||||
// TODO: Refactor into batch indexes instead.
|
// TODO: Refactor into batch indexes instead.
|
||||||
pub fn index(&self, db: &Database) -> QueryResult<()> {
|
// TODO: Refactor so all index methods take consistent arguments
|
||||||
|
// like NewEpisode.index wants Sqliteconnection where the other take a Database
|
||||||
|
pub fn index(&self, con: &SqliteConnection) -> QueryResult<()> {
|
||||||
use schema::episode::dsl::*;
|
use schema::episode::dsl::*;
|
||||||
|
|
||||||
let ep = {
|
let ep = {
|
||||||
let tempdb = db.lock().unwrap();
|
// let tempdb = db.lock().unwrap();
|
||||||
dbqueries::get_episode_from_uri(&tempdb, self.uri.unwrap())
|
// dbqueries::get_episode_from_uri(&tempdb, self.uri.unwrap())
|
||||||
|
dbqueries::get_episode_from_uri(con, self.uri.unwrap())
|
||||||
};
|
};
|
||||||
|
|
||||||
match ep {
|
match ep {
|
||||||
Ok(foo) => if foo.title() != self.title
|
Ok(foo) => if foo.title() != self.title
|
||||||
|| foo.published_date() != self.published_date.as_ref().map(|x| x.as_str())
|
|| foo.published_date() != self.published_date.as_ref().map(|x| x.as_str())
|
||||||
{
|
{
|
||||||
let tempdb = db.lock().unwrap();
|
// let tempdb = db.lock().unwrap();
|
||||||
diesel::replace_into(episode)
|
diesel::replace_into(episode).values(self).execute(con)?;
|
||||||
.values(self)
|
// .execute(&*tempdb)?;
|
||||||
.execute(&*tempdb)?;
|
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let tempdb = db.lock().unwrap();
|
// let tempdb = db.lock().unwrap();
|
||||||
diesel::insert_into(episode).values(self).execute(&*tempdb)?;
|
diesel::insert_into(episode).values(self).execute(con)?;
|
||||||
|
// .execute(&*tempdb)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user