diff --git a/hammond-data/src/feed.rs b/hammond-data/src/feed.rs index 3c35770..2395779 100644 --- a/hammond-data/src/feed.rs +++ b/hammond-data/src/feed.rs @@ -8,8 +8,8 @@ use rss; use dbqueries; use errors::*; -use models::{Index, IndexState, Update}; -use models::{NewEpisode, NewPodcast, Podcast}; +use models::{IndexState, Update}; +use models::{NewPodcast, Podcast}; use pipeline::*; #[derive(Debug)] @@ -29,21 +29,7 @@ impl Feed { /// Index the contents of the RSS `Feed` into the database. pub fn index(&self) -> Result<()> { let pd = self.parse_podcast().into_podcast()?; - self.index_channel_items_sync(&pd) - } - - // TODO: Refactor transcactions and find a way to do it in parallel. - #[allow(dead_code)] - fn index_channel_items(&self, pd: &Podcast) -> Result<()> { - let episodes = self.parse_channel_items(pd); - - episodes.iter().for_each(|x| { - if let Err(err) = x.index() { - error!("Failed to index episode: {:?}.", x.title()); - error!("Error msg: {}", err); - }; - }); - Ok(()) + self.index_channel_items(&pd) } #[allow(dead_code)] @@ -57,18 +43,7 @@ impl Feed { } #[allow(dead_code)] - fn parse_channel_items(&self, pd: &Podcast) -> Vec { - let items = self.channel.items(); - let new_episodes: Vec<_> = items - .par_iter() - .filter_map(|item| NewEpisode::new(item, pd.id()).ok()) - .collect(); - - new_episodes - } - - #[allow(dead_code)] - fn index_channel_items_sync(&self, pd: &Podcast) -> Result<()> { + fn index_channel_items(&self, pd: &Podcast) -> Result<()> { let items = self.channel.items(); let (insert, update): (Vec<_>, Vec<_>) = items .into_iter() diff --git a/hammond-data/src/models/new_episode.rs b/hammond-data/src/models/new_episode.rs index ca8e1a4..cae96db 100644 --- a/hammond-data/src/models/new_episode.rs +++ b/hammond-data/src/models/new_episode.rs @@ -101,6 +101,7 @@ impl Index for NewEpisode { impl NewEpisode { /// Parses an `rss::Item` into a `NewEpisode` Struct. + #[allow(dead_code)] pub(crate) fn new(item: &rss::Item, podcast_id: i32) -> Result { NewEpisodeMinimal::new(item, podcast_id).map(|ep| ep.into_new_episode(item)) } diff --git a/hammond-data/src/pipeline.rs b/hammond-data/src/pipeline.rs index 41142f4..cc8bfd3 100644 --- a/hammond-data/src/pipeline.rs +++ b/hammond-data/src/pipeline.rs @@ -13,7 +13,7 @@ use rss; use Source; use dbqueries; use errors::*; -use models::{IndexState, Insert, NewEpisode, NewEpisodeMinimal, Update}; +use models::{IndexState, NewEpisode, NewEpisodeMinimal}; // use models::new_episode::NewEpisodeMinimal; // use Feed; @@ -49,11 +49,8 @@ pub fn pipeline>(sources: S, ignore_etags: bool) } #[allow(dead_code)] -pub(crate) fn determine_episode_state( - ep: NewEpisodeMinimal, - item: &rss::Item, -) -> Result> { - // determine if feed exists +fn determine_ep_state(ep: NewEpisodeMinimal, item: &rss::Item) -> Result> { + // Check if feed exists let exists = dbqueries::episode_exists(ep.title(), ep.podcast_id())?; if !exists { @@ -70,26 +67,10 @@ pub(crate) fn determine_episode_state( } } -#[allow(dead_code)] -pub(crate) fn model_state(state: IndexState) -> Result<()> { - match state { - IndexState::NotChanged => Ok(()), - IndexState::Index(t) => t.insert(), - IndexState::Update((t, rowid)) => t.update(rowid), - } -} - -#[allow(dead_code)] -pub(crate) fn model_state_future( - state: IndexState, -) -> Box> { - Box::new(result(model_state(state))) -} - #[allow(dead_code)] pub(crate) fn glue(item: &rss::Item, id: i32) -> Result> { let e = NewEpisodeMinimal::new(item, id)?; - determine_episode_state(e, &item) + determine_ep_state(e, &item) } // Weird magic from #rust irc channel