From b3460b15a2c08236be78cf0f60a8774e50195ac1 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 16 Jan 2018 13:44:33 +0200 Subject: [PATCH] hammond_data::Feed: add parse_podcast_future method. --- hammond-data/src/feed.rs | 17 +++++++++++++++++ hammond-data/src/lib.rs | 1 + hammond-data/src/models/queryables.rs | 1 + hammond-data/src/pipeline.rs | 10 ++++++---- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/hammond-data/src/feed.rs b/hammond-data/src/feed.rs index 11bd6bc..f10debe 100644 --- a/hammond-data/src/feed.rs +++ b/hammond-data/src/feed.rs @@ -2,6 +2,8 @@ use rayon::prelude::*; use diesel::prelude::*; +use futures::prelude::*; +use futures::future::*; use rayon::iter::IntoParallelIterator; use rss; @@ -42,6 +44,17 @@ impl Feed { self.index_channel_items(&pd) } + /// Docs + // FIXME: docs + // FIXME: lifetime stuff + pub fn index_future(self) -> Box> { + let indx = self.parse_podcast_futture() + .and_then(|pd| pd.into_podcast()) + .and_then(move |pd| self.index_channel_items(&pd)); + + Box::new(indx) + } + // TODO: Refactor transcactions and find a way to do it in parallel. fn index_channel_items(&self, pd: &Podcast) -> Result<()> { let episodes = self.parse_channel_items(pd); @@ -64,6 +77,10 @@ impl Feed { parser::new_podcast(&self.channel, self.source_id) } + fn parse_podcast_futture(&self) -> Box> { + Box::new(ok(self.parse_podcast())) + } + fn parse_channel_items(&self, pd: &Podcast) -> Vec { let items = self.channel.items(); let new_episodes: Vec<_> = items diff --git a/hammond-data/src/lib.rs b/hammond-data/src/lib.rs index 047d265..5507eee 100644 --- a/hammond-data/src/lib.rs +++ b/hammond-data/src/lib.rs @@ -71,6 +71,7 @@ mod parser; mod schema; pub use models::queryables::{Episode, EpisodeWidgetQuery, Podcast, PodcastCoverQuery, Source}; +// pub use feed::Feed; /// [XDG Base Direcotory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) Paths. #[allow(missing_debug_implementations)] diff --git a/hammond-data/src/models/queryables.rs b/hammond-data/src/models/queryables.rs index 0b93a3c..d6f8390 100644 --- a/hammond-data/src/models/queryables.rs +++ b/hammond-data/src/models/queryables.rs @@ -716,6 +716,7 @@ impl Source { Ok(Feed::from_channel_source(chan, self.id)) } + // FIXME: /// Docs pub fn into_fututre_feed( self, diff --git a/hammond-data/src/pipeline.rs b/hammond-data/src/pipeline.rs index bf51449..2510248 100644 --- a/hammond-data/src/pipeline.rs +++ b/hammond-data/src/pipeline.rs @@ -1,14 +1,16 @@ +// FIXME: //! Docs. -use errors::Error; -use Source; - use tokio_core::reactor::Core; use hyper::Client; use hyper_tls::HttpsConnector; use futures::prelude::*; use futures::future::*; +use errors::Error; +use Source; +// use Feed; + // Weird magic from #rust irc channel // kudos to remexre fn collect_futures( @@ -60,7 +62,7 @@ mod dirtyhack { .into_iter() // FIXME: Make proper indexing futures instead of wrapping up existing // blocking functions - .map(|s| s.into_fututre_feed(&client, ignore_etags).map(|feed| feed.index())) + .map(|s| s.into_fututre_feed(&client, ignore_etags).map(|feed| feed.index_future())) .collect(); let f = core.run(collect_futures(list))?;