Refactored refresh_feed.

This commit is contained in:
Jordan Petridis
2017-11-04 13:56:23 +02:00
parent 7a1b272d9e
commit a9dec8dbe8
4 changed files with 21 additions and 18 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ fn on_add_bttn_clicked(db: &Database, stack: &gtk::Stack, url: &str) {
if let Ok(s) = source {
// update the db
utils::refresh_feed(db, stack, Some(Box::new(vec![s])));
utils::refresh_feed(db, stack, Some(vec![s]));
} else {
error!("Expected Error, feed probably already exists.");
error!("Error: {:?}", source.unwrap_err());
+2 -1
View File
@@ -12,8 +12,9 @@ extern crate hammond_downloader;
extern crate log;
extern crate loggerv;
extern crate open;
extern crate rayon;
// extern crate rayon;
// use rayon::prelude::*;
use log::LogLevel;
use hammond_data::dbcheckup;
+9 -12
View File
@@ -1,6 +1,5 @@
use glib;
use gtk;
use rayon::prelude::*;
use hammond_data::index_feed;
use hammond_data::models::Source;
@@ -18,26 +17,24 @@ thread_local!(
gtk::Stack,
Receiver<bool>)>> = RefCell::new(None));
pub fn refresh_feed(db: &Database, stack: &gtk::Stack, source: Option<Box<Vec<Source>>>) {
/// Update the rss feed(s) originating from `Source`.
/// If `source` is None, Fetches all the `Source` entries in the database and updates them.
/// When It's done,it queues up a `podcast_view` refresh.
pub fn refresh_feed(db: &Database, stack: &gtk::Stack, source: Option<Vec<Source>>) {
// Create a async channel.
let (sender, receiver) = channel();
// Pass the desired arguments into the Local Thread Storage.
GLOBAL.with(clone!(db, stack => move |global| {
*global.borrow_mut() = Some((db, stack, receiver));
}));
// TODO: add timeout option and error reporting.
thread::spawn(clone!(db => move || {
let feeds = {
if let Some(mut boxed_vec) = source {
let f = boxed_vec
.par_iter_mut()
.filter_map(|mut s| {
index_feed::refresh_source(&db, &mut s).ok()
})
.collect();
Ok(f)
if let Some(mut vec) = source {
Ok(index_feed::fetch_feeds(&db, &mut vec))
} else {
index_feed::fetch_feeds(&db)
index_feed::fetch_all_feeds(&db)
}
};