From 0e8ea41ca7de21a667f7730214345097fa65edcf Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 18 Oct 2017 05:53:52 +0300 Subject: [PATCH] Wired add button, Fixed db refresh and changed the index API. --- hammond-cli/src/main.rs | 7 ++++--- hammond-data/src/index_feed.rs | 21 +++++++++------------ hammond-gtk/gtk/EpisodeWidget.ui | 4 +++- hammond-gtk/gtk/headerbar.ui | 3 +-- hammond-gtk/gtk/podcast_widget.ui | 1 - hammond-gtk/src/main.rs | 27 ++++++++++++++++++++------- 6 files changed, 37 insertions(+), 26 deletions(-) diff --git a/hammond-cli/src/main.rs b/hammond-cli/src/main.rs index 1894804..deebc72 100644 --- a/hammond-cli/src/main.rs +++ b/hammond-cli/src/main.rs @@ -16,8 +16,8 @@ use hammond_data::errors::*; use hammond_data::index_feed; use hammond_downloader::downloader; -// Should probably had made an Enum instead. -// TODO: Refactor to enum, add --force for update +use std::sync::{Arc, Mutex}; + #[derive(StructOpt, Debug)] #[structopt(name = "example", about = "An example of StructOpt usage.")] struct Opt { @@ -50,7 +50,8 @@ fn run() -> Result<()> { if args.up { let db = hammond_data::establish_connection(); - index_feed::index_loop(db, false)?; + let db = Arc::new(Mutex::new(db)); + index_feed::index_loop(db.clone(), false)?; } if args.dl >= 0 { diff --git a/hammond-data/src/index_feed.rs b/hammond-data/src/index_feed.rs index 9394143..15aa696 100644 --- a/hammond-data/src/index_feed.rs +++ b/hammond-data/src/index_feed.rs @@ -78,13 +78,11 @@ fn insert_return_episode(con: &SqliteConnection, ep: &NewEpisode) -> Result Result<()> { - let m = Arc::new(Mutex::new(db)); - - let mut f = fetch_feeds(m.clone(), force)?; +pub fn index_loop(db: Arc>, force: bool) -> Result<()> { + let mut f = fetch_feeds(db.clone(), force)?; f.par_iter_mut().for_each(|&mut (ref mut req, ref source)| { - complete_index_from_source(req, source, m.clone()).unwrap(); + complete_index_from_source(req, source, db.clone()).unwrap(); }); Ok(()) @@ -249,7 +247,8 @@ mod tests { #[test] /// Insert feeds and update/index them. fn test_index_loop() { - let TempDB(_tmp_dir, db_path, db) = get_temp_db(); + let TempDB(_tmp_dir, _db_path, db) = get_temp_db(); + let db = Arc::new(Mutex::new(db)); let inpt = vec![ "https://request-for-explanation.github.io/podcast/rss.xml", @@ -259,16 +258,14 @@ mod tests { ]; inpt.iter().for_each(|feed| { - index_source(&db, &NewSource::new_with_uri(feed)).unwrap() + let tempdb = db.lock().unwrap(); + index_source(&tempdb, &NewSource::new_with_uri(feed)).unwrap() }); - index_loop(db, true).unwrap(); - - // index_loop takes oweneship of the dbconnection in order to create mutexes. - let db = SqliteConnection::establish(db_path.to_str().unwrap()).unwrap(); + index_loop(db.clone(), true).unwrap(); // Run again to cover Unique constrains erros. - index_loop(db, true).unwrap(); + index_loop(db.clone(), true).unwrap(); } #[test] diff --git a/hammond-gtk/gtk/EpisodeWidget.ui b/hammond-gtk/gtk/EpisodeWidget.ui index 96cbf12..647d513 100644 --- a/hammond-gtk/gtk/EpisodeWidget.ui +++ b/hammond-gtk/gtk/EpisodeWidget.ui @@ -44,7 +44,7 @@ 3 - False + True False 1 @@ -78,6 +78,7 @@ False False 5 + end 1 @@ -100,6 +101,7 @@ False False 5 + end 2 diff --git a/hammond-gtk/gtk/headerbar.ui b/hammond-gtk/gtk/headerbar.ui index 84d61b4..0a0c22e 100644 --- a/hammond-gtk/gtk/headerbar.ui +++ b/hammond-gtk/gtk/headerbar.ui @@ -52,13 +52,12 @@ True - False + True True Add True - False True False