hammond_data: Remove Source dependancy from Feed struct.
This commit is contained in:
parent
1dd25f91fd
commit
ee9cede921
@ -1,4 +1,4 @@
|
|||||||
//! Index and retrieve Feeds.
|
//! Index Feeds.
|
||||||
|
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
@ -20,20 +20,20 @@ use errors::*;
|
|||||||
/// that corresponds to the `Source.uri` field.
|
/// that corresponds to the `Source.uri` field.
|
||||||
pub struct Feed {
|
pub struct Feed {
|
||||||
channel: rss::Channel,
|
channel: rss::Channel,
|
||||||
source: Source,
|
source_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Feed {
|
impl Feed {
|
||||||
/// Constructor that consumes a `Source` and returns the corresponding `Feed` struct.
|
/// Constructor that consumes a `Source` and returns the corresponding `Feed` struct.
|
||||||
pub fn from_source(s: Source) -> Result<Feed> {
|
pub fn from_source(s: &mut Source) -> Result<Feed> {
|
||||||
s.into_feed(false)
|
s.into_feed(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructor that consumes a `Source` and a `rss::Channel` returns a `Feed` struct.
|
/// Constructor that consumes a `Source` and a `rss::Channel` returns a `Feed` struct.
|
||||||
pub fn from_channel_source(chan: rss::Channel, s: Source) -> Feed {
|
pub fn from_channel_source(chan: rss::Channel, s: i32) -> Feed {
|
||||||
Feed {
|
Feed {
|
||||||
channel: chan,
|
channel: chan,
|
||||||
source: s,
|
source_id: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ impl Feed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_channel(&self) -> NewPodcast {
|
fn parse_channel(&self) -> NewPodcast {
|
||||||
parser::new_podcast(&self.channel, *self.source.id())
|
parser::new_podcast(&self.channel, self.source_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_channel_items(&self, pd: &Podcast) -> Vec<NewEpisode> {
|
fn parse_channel_items(&self, pd: &Podcast) -> Vec<NewEpisode> {
|
||||||
@ -111,7 +111,7 @@ pub fn index(feed: &Feed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Consume a `Source` and return a `Feed`.
|
/// Consume a `Source` and return a `Feed`.
|
||||||
fn fetch(source: Source) -> Result<Feed> {
|
fn fetch(source: &mut Source) -> Result<Feed> {
|
||||||
Feed::from_source(source)
|
Feed::from_source(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +119,8 @@ fn fetch(source: Source) -> Result<Feed> {
|
|||||||
pub fn index_loop<S: IntoParallelIterator<Item = Source>>(sources: S) {
|
pub fn index_loop<S: IntoParallelIterator<Item = Source>>(sources: S) {
|
||||||
sources
|
sources
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.filter_map(|x| {
|
.filter_map(|mut x| {
|
||||||
let foo = fetch(x);
|
let foo = fetch(&mut x);
|
||||||
if let Err(err) = foo {
|
if let Err(err) = foo {
|
||||||
error!("Error: {}", err);
|
error!("Error: {}", err);
|
||||||
None
|
None
|
||||||
@ -203,7 +203,7 @@ mod tests {
|
|||||||
let feed = fs::File::open(path).unwrap();
|
let feed = fs::File::open(path).unwrap();
|
||||||
// parse it into a channel
|
// parse it into a channel
|
||||||
let chan = rss::Channel::read_from(BufReader::new(feed)).unwrap();
|
let chan = rss::Channel::read_from(BufReader::new(feed)).unwrap();
|
||||||
Feed::from_channel_source(chan, s)
|
Feed::from_channel_source(chan, *s.id())
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -221,8 +221,8 @@ mod tests {
|
|||||||
truncate_db().unwrap();
|
truncate_db().unwrap();
|
||||||
let url = "https://feeds.feedburner.com/InterceptedWithJeremyScahill";
|
let url = "https://feeds.feedburner.com/InterceptedWithJeremyScahill";
|
||||||
|
|
||||||
let s1 = Source::from_url(url).unwrap();
|
let mut s1 = Source::from_url(url).unwrap();
|
||||||
let s2 = Source::from_url(url).unwrap();
|
let mut s2 = Source::from_url(url).unwrap();
|
||||||
assert_eq!(s1, s2);
|
assert_eq!(s1, s2);
|
||||||
assert_eq!(s1.id(), s2.id());
|
assert_eq!(s1.id(), s2.id());
|
||||||
|
|
||||||
|
|||||||
@ -670,7 +670,7 @@ impl<'a> Source {
|
|||||||
///
|
///
|
||||||
/// Consumes `self` and Returns the corresponding `Feed` Object.
|
/// Consumes `self` and Returns the corresponding `Feed` Object.
|
||||||
// TODO: Refactor into TryInto once it lands on stable.
|
// TODO: Refactor into TryInto once it lands on stable.
|
||||||
pub fn into_feed(mut self, ignore_etags: bool) -> Result<Feed> {
|
pub fn into_feed(&mut self, ignore_etags: bool) -> Result<Feed> {
|
||||||
use reqwest::header::{EntityTag, Headers, HttpDate, IfModifiedSince, IfNoneMatch};
|
use reqwest::header::{EntityTag, Headers, HttpDate, IfModifiedSince, IfNoneMatch};
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
|
||||||
@ -725,7 +725,7 @@ impl<'a> Source {
|
|||||||
req.read_to_string(&mut buf)?;
|
req.read_to_string(&mut buf)?;
|
||||||
let chan = Channel::from_str(&buf)?;
|
let chan = Channel::from_str(&buf)?;
|
||||||
|
|
||||||
Ok(Feed::from_channel_source(chan, self))
|
Ok(Feed::from_channel_source(chan, self.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a new `Source` with the given `uri` and index it.
|
/// Construct a new `Source` with the given `uri` and index it.
|
||||||
|
|||||||
@ -11,7 +11,6 @@ use hyper_tls::HttpsConnector;
|
|||||||
|
|
||||||
use futures::{Future, Stream};
|
use futures::{Future, Stream};
|
||||||
// use futures::future::join_all;
|
// use futures::future::join_all;
|
||||||
use tokio_core::reactor::Core;
|
|
||||||
|
|
||||||
// use std::io::{self, Write};
|
// use std::io::{self, Write};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -63,6 +62,7 @@ fn res_to_channel(res: hyper::Response) -> Box<Future<Item = rss::Channel, Error
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
// use futures::future::result;
|
// use futures::future::result;
|
||||||
|
use tokio_core::reactor::Core;
|
||||||
|
|
||||||
use database::truncate_db;
|
use database::truncate_db;
|
||||||
use Source;
|
use Source;
|
||||||
|
|||||||
@ -229,7 +229,7 @@ mod tests {
|
|||||||
let url = "http://www.newrustacean.com/feed.xml";
|
let url = "http://www.newrustacean.com/feed.xml";
|
||||||
|
|
||||||
// Create and index a source
|
// Create and index a source
|
||||||
let source = Source::from_url(url).unwrap();
|
let mut source = Source::from_url(url).unwrap();
|
||||||
// Copy it's id
|
// Copy it's id
|
||||||
let sid = source.id().clone();
|
let sid = source.id().clone();
|
||||||
|
|
||||||
|
|||||||
@ -139,7 +139,7 @@ mod tests {
|
|||||||
let url = "http://www.newrustacean.com/feed.xml";
|
let url = "http://www.newrustacean.com/feed.xml";
|
||||||
|
|
||||||
// Create and index a source
|
// Create and index a source
|
||||||
let source = Source::from_url(url).unwrap();
|
let mut source = Source::from_url(url).unwrap();
|
||||||
// Copy it's id
|
// Copy it's id
|
||||||
let sid = source.id().clone();
|
let sid = source.id().clone();
|
||||||
|
|
||||||
|
|||||||
@ -81,7 +81,7 @@ mod tests {
|
|||||||
let url = "http://www.newrustacean.com/feed.xml";
|
let url = "http://www.newrustacean.com/feed.xml";
|
||||||
|
|
||||||
// Create and index a source
|
// Create and index a source
|
||||||
let source = Source::from_url(url).unwrap();
|
let mut source = Source::from_url(url).unwrap();
|
||||||
// Copy it's id
|
// Copy it's id
|
||||||
let sid = source.id().clone();
|
let sid = source.id().clone();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user