Upgrade Diesel to 1.1
This commit is contained in:
@@ -13,8 +13,6 @@ error-chain = "0.11.0"
|
||||
itertools = "0.7.6"
|
||||
lazy_static = "1.0.0"
|
||||
log = "0.4.1"
|
||||
r2d2 = "0.8.2"
|
||||
r2d2-diesel = "1.0.0"
|
||||
rayon = "0.9.0"
|
||||
reqwest = "0.8.2"
|
||||
rfc822_sanitizer = "0.3.3"
|
||||
@@ -28,12 +26,12 @@ hyper-tls = "0.1.2"
|
||||
native-tls = "0.1.4"
|
||||
|
||||
[dependencies.diesel]
|
||||
features = ["sqlite"]
|
||||
version = "1.0.0"
|
||||
features = ["sqlite", "r2d2"]
|
||||
version = "1.1.1"
|
||||
|
||||
[dependencies.diesel_migrations]
|
||||
features = ["sqlite"]
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.4.1"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! Database Setup. This is only public to help with some unit tests.
|
||||
|
||||
use diesel::prelude::*;
|
||||
use r2d2;
|
||||
use r2d2_diesel::ConnectionManager;
|
||||
use diesel::r2d2;
|
||||
use diesel::r2d2::ConnectionManager;
|
||||
|
||||
use std::io;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -13,7 +13,7 @@ pub fn get_sources() -> Result<Vec<Source>> {
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
source.load::<Source>(&*con).map_err(From::from)
|
||||
source.load::<Source>(&con).map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_podcasts() -> Result<Vec<Podcast>> {
|
||||
@@ -21,7 +21,7 @@ pub fn get_podcasts() -> Result<Vec<Podcast>> {
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
podcast.load::<Podcast>(&*con).map_err(From::from)
|
||||
podcast.load::<Podcast>(&con).map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn get_episodes() -> Result<Vec<Episode>> {
|
||||
@@ -31,7 +31,7 @@ pub fn get_episodes() -> Result<Vec<Episode>> {
|
||||
|
||||
episode
|
||||
.order(epoch.desc())
|
||||
.load::<Episode>(&*con)
|
||||
.load::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ pub(crate) fn get_downloaded_episodes() -> Result<Vec<EpisodeCleanerQuery>> {
|
||||
episode
|
||||
.select((rowid, local_uri, played))
|
||||
.filter(local_uri.is_not_null())
|
||||
.load::<EpisodeCleanerQuery>(&*con)
|
||||
.load::<EpisodeCleanerQuery>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ pub(crate) fn get_downloaded_episodes() -> Result<Vec<EpisodeCleanerQuery>> {
|
||||
// let con = db.get()?;
|
||||
// episode
|
||||
// .filter(played.is_not_null())
|
||||
// .load::<Episode>(&*con)
|
||||
// .load::<Episode>(&con)
|
||||
// .map_err(From::from)
|
||||
// }
|
||||
|
||||
@@ -66,7 +66,7 @@ pub(crate) fn get_played_cleaner_episodes() -> Result<Vec<EpisodeCleanerQuery>>
|
||||
episode
|
||||
.select((rowid, local_uri, played))
|
||||
.filter(played.is_not_null())
|
||||
.load::<EpisodeCleanerQuery>(&*con)
|
||||
.load::<EpisodeCleanerQuery>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ pub fn get_episode_from_rowid(ep_id: i32) -> Result<Episode> {
|
||||
|
||||
episode
|
||||
.filter(rowid.eq(ep_id))
|
||||
.get_result::<Episode>(&*con)
|
||||
.get_result::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ pub fn get_episode_local_uri_from_id(ep_id: i32) -> Result<Option<String>> {
|
||||
episode
|
||||
.filter(rowid.eq(ep_id))
|
||||
.select(local_uri)
|
||||
.get_result::<Option<String>>(&*con)
|
||||
.get_result::<Option<String>>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ pub fn get_episodes_widgets_with_limit(limit: u32) -> Result<Vec<EpisodeWidgetQu
|
||||
))
|
||||
.order(episode::epoch.desc())
|
||||
.limit(i64::from(limit))
|
||||
.load::<EpisodeWidgetQuery>(&*con)
|
||||
.load::<EpisodeWidgetQuery>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ pub fn get_podcast_from_id(pid: i32) -> Result<Podcast> {
|
||||
|
||||
podcast
|
||||
.filter(id.eq(pid))
|
||||
.get_result::<Podcast>(&*con)
|
||||
.get_result::<Podcast>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ pub fn get_podcast_cover_from_id(pid: i32) -> Result<PodcastCoverQuery> {
|
||||
podcast
|
||||
.select((id, title, image_uri))
|
||||
.filter(id.eq(pid))
|
||||
.get_result::<PodcastCoverQuery>(&*con)
|
||||
.get_result::<PodcastCoverQuery>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ pub fn get_pd_episodes(parent: &Podcast) -> Result<Vec<Episode>> {
|
||||
|
||||
Episode::belonging_to(parent)
|
||||
.order(epoch.desc())
|
||||
.load::<Episode>(&*con)
|
||||
.load::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ pub fn get_pd_episodeswidgets(parent: &Podcast) -> Result<Vec<EpisodeWidgetQuery
|
||||
.filter(podcast_id.eq(parent.id()))
|
||||
// .group_by(epoch)
|
||||
.order(epoch.desc())
|
||||
.load::<EpisodeWidgetQuery>(&*con)
|
||||
.load::<EpisodeWidgetQuery>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ pub fn get_pd_unplayed_episodes(parent: &Podcast) -> Result<Vec<Episode>> {
|
||||
Episode::belonging_to(parent)
|
||||
.filter(played.is_null())
|
||||
.order(epoch.desc())
|
||||
.load::<Episode>(&*con)
|
||||
.load::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ pub fn get_pd_unplayed_episodes(parent: &Podcast) -> Result<Vec<Episode>> {
|
||||
// Episode::belonging_to(parent)
|
||||
// .order(epoch.desc())
|
||||
// .limit(i64::from(limit))
|
||||
// .load::<Episode>(&*con)
|
||||
// .load::<Episode>(&con)
|
||||
// .map_err(From::from)
|
||||
// }
|
||||
|
||||
@@ -195,7 +195,7 @@ pub fn get_source_from_uri(uri_: &str) -> Result<Source> {
|
||||
|
||||
source
|
||||
.filter(uri.eq(uri_))
|
||||
.get_result::<Source>(&*con)
|
||||
.get_result::<Source>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ pub fn get_podcast_from_source_id(sid: i32) -> Result<Podcast> {
|
||||
|
||||
podcast
|
||||
.filter(source_id.eq(sid))
|
||||
.get_result::<Podcast>(&*con)
|
||||
.get_result::<Podcast>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ pub fn get_episode_from_pk(title_: &str, pid: i32) -> Result<Episode> {
|
||||
episode
|
||||
.filter(title.eq(title_))
|
||||
.filter(podcast_id.eq(pid))
|
||||
.get_result::<Episode>(&*con)
|
||||
.get_result::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ pub(crate) fn get_episode_minimal_from_pk(title_: &str, pid: i32) -> Result<Epis
|
||||
.select((rowid, title, uri, epoch, duration, guid, podcast_id))
|
||||
.filter(title.eq(title_))
|
||||
.filter(podcast_id.eq(pid))
|
||||
.get_result::<EpisodeMinimal>(&*con)
|
||||
.get_result::<EpisodeMinimal>(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -251,19 +251,19 @@ pub(crate) fn remove_feed(pd: &Podcast) -> Result<()> {
|
||||
fn delete_source(con: &SqliteConnection, source_id: i32) -> QueryResult<usize> {
|
||||
use schema::source::dsl::*;
|
||||
|
||||
diesel::delete(source.filter(id.eq(source_id))).execute(&*con)
|
||||
diesel::delete(source.filter(id.eq(source_id))).execute(con)
|
||||
}
|
||||
|
||||
fn delete_podcast(con: &SqliteConnection, podcast_id: i32) -> QueryResult<usize> {
|
||||
use schema::podcast::dsl::*;
|
||||
|
||||
diesel::delete(podcast.filter(id.eq(podcast_id))).execute(&*con)
|
||||
diesel::delete(podcast.filter(id.eq(podcast_id))).execute(con)
|
||||
}
|
||||
|
||||
fn delete_podcast_episodes(con: &SqliteConnection, parent_id: i32) -> QueryResult<usize> {
|
||||
use schema::episode::dsl::*;
|
||||
|
||||
diesel::delete(episode.filter(podcast_id.eq(parent_id))).execute(&*con)
|
||||
diesel::delete(episode.filter(podcast_id.eq(parent_id))).execute(con)
|
||||
}
|
||||
|
||||
pub(crate) fn podcast_exists(source_id_: i32) -> Result<bool> {
|
||||
@@ -275,7 +275,7 @@ pub(crate) fn podcast_exists(source_id_: i32) -> Result<bool> {
|
||||
let con = db.get()?;
|
||||
|
||||
select(exists(podcast.filter(source_id.eq(source_id_))))
|
||||
.get_result(&*con)
|
||||
.get_result(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -289,21 +289,21 @@ pub(crate) fn episode_exists(title_: &str, podcast_id_: i32) -> Result<bool> {
|
||||
let con = db.get()?;
|
||||
|
||||
select(exists(episode.filter(podcast_id.eq(podcast_id_)).filter(title.eq(title_))))
|
||||
.get_result(&*con)
|
||||
.get_result(&con)
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<()> {
|
||||
use schema::episode::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
// pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<()> {
|
||||
// use schema::episode::dsl::*;
|
||||
// let db = connection();
|
||||
// let con = db.get()?;
|
||||
|
||||
diesel::insert_into(episode)
|
||||
.values(eps)
|
||||
.execute(&*con)
|
||||
.map_err(From::from)
|
||||
.map(|_| ())
|
||||
}
|
||||
// diesel::insert_into(episode)
|
||||
// .values(eps)
|
||||
// .execute(&con)
|
||||
// .map_err(From::from)
|
||||
// .map(|_| ())
|
||||
// }
|
||||
|
||||
pub fn update_none_to_played_now(parent: &Podcast) -> Result<usize> {
|
||||
use schema::episode::dsl::*;
|
||||
@@ -314,7 +314,7 @@ pub fn update_none_to_played_now(parent: &Podcast) -> Result<usize> {
|
||||
con.transaction(|| -> Result<usize> {
|
||||
diesel::update(Episode::belonging_to(parent).filter(played.is_null()))
|
||||
.set(played.eq(Some(epoch_now)))
|
||||
.execute(&*con)
|
||||
.execute(&con)
|
||||
.map_err(From::from)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use diesel;
|
||||
use diesel::r2d2;
|
||||
use diesel_migrations::RunMigrationsError;
|
||||
use hyper;
|
||||
use native_tls;
|
||||
use r2d2;
|
||||
use reqwest;
|
||||
use rss;
|
||||
|
||||
@@ -10,9 +10,10 @@ use std::io;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
R2D2Error(r2d2::Error);
|
||||
DieselResultError(diesel::result::Error);
|
||||
DieselMigrationError(RunMigrationsError);
|
||||
R2D2Error(r2d2::Error);
|
||||
R2D2PoolError(r2d2::PoolError);
|
||||
RSSError(rss::Error);
|
||||
ReqError(reqwest::Error);
|
||||
HyperError(hyper::Error);
|
||||
|
||||
@@ -4,9 +4,9 @@ use futures::future::*;
|
||||
use itertools::{Either, Itertools};
|
||||
use rss;
|
||||
|
||||
use dbqueries;
|
||||
// use dbqueries;
|
||||
use errors::*;
|
||||
use models::{IndexState, Update};
|
||||
use models::{IndexState, Insert, Update};
|
||||
use models::{NewEpisode, NewPodcast, Podcast};
|
||||
use pipeline::*;
|
||||
|
||||
@@ -26,7 +26,7 @@ pub struct Feed {
|
||||
|
||||
impl Feed {
|
||||
/// Index the contents of the RSS `Feed` into the database.
|
||||
pub fn index(self) -> Box<Future<Item = (), Error = Error>> {
|
||||
pub fn index(self) -> Box<Future<Item = (), Error = Error> + Send> {
|
||||
let fut = self.parse_podcast_async()
|
||||
.and_then(|pd| pd.to_podcast())
|
||||
.and_then(move |pd| self.index_channel_items(&pd));
|
||||
@@ -38,16 +38,23 @@ impl Feed {
|
||||
NewPodcast::new(&self.channel, self.source_id)
|
||||
}
|
||||
|
||||
fn parse_podcast_async(&self) -> Box<FutureResult<NewPodcast, Error>> {
|
||||
fn parse_podcast_async(&self) -> Box<Future<Item = NewPodcast, Error = Error> + Send> {
|
||||
Box::new(ok(self.parse_podcast()))
|
||||
}
|
||||
|
||||
fn index_channel_items(&self, pd: &Podcast) -> Box<Future<Item = (), Error = Error>> {
|
||||
fn index_channel_items(&self, pd: &Podcast) -> Box<Future<Item = (), Error = Error> + Send> {
|
||||
let fut = self.get_stuff(pd)
|
||||
.and_then(|(insert, update)| {
|
||||
if !insert.is_empty() {
|
||||
info!("Indexing {} episodes.", insert.len());
|
||||
dbqueries::index_new_episodes(insert.as_slice())?;
|
||||
// dbqueries::index_new_episodes(insert.as_slice())?;
|
||||
// FIXME: workaround cause of a diesel 1.1 reggression.
|
||||
insert.iter().for_each(|ep| {
|
||||
if let Err(err) = ep.insert() {
|
||||
error!("Failed to index episode: {:?}.", ep.title());
|
||||
error!("Error msg: {}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
Ok((insert, update))
|
||||
})
|
||||
@@ -69,7 +76,7 @@ impl Feed {
|
||||
Box::new(fut)
|
||||
}
|
||||
|
||||
fn get_stuff(&self, pd: &Podcast) -> Box<Future<Item = InsertUpdate, Error = Error>> {
|
||||
fn get_stuff(&self, pd: &Podcast) -> Box<Future<Item = InsertUpdate, Error = Error> + Send> {
|
||||
let (insert, update): (Vec<_>, Vec<_>) = self.channel
|
||||
.items()
|
||||
.into_iter()
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
unused_parens, while_true)]
|
||||
#![deny(missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts)]
|
||||
#![deny(unused_extern_crates, unused)]
|
||||
#![deny(unused_extern_crates, unused)]
|
||||
|
||||
// #![feature(conservative_impl_trait)]
|
||||
|
||||
@@ -38,12 +39,11 @@ extern crate log;
|
||||
extern crate ammonia;
|
||||
extern crate chrono;
|
||||
extern crate futures;
|
||||
// extern crate futures_cpupool;
|
||||
extern crate hyper;
|
||||
extern crate hyper_tls;
|
||||
extern crate itertools;
|
||||
extern crate native_tls;
|
||||
extern crate r2d2;
|
||||
extern crate r2d2_diesel;
|
||||
extern crate rayon;
|
||||
extern crate reqwest;
|
||||
extern crate rfc822_sanitizer;
|
||||
|
||||
@@ -54,7 +54,7 @@ impl Insert for NewEpisode {
|
||||
info!("Indexing {:?}", self.title);
|
||||
diesel::insert_into(episode)
|
||||
.values(self)
|
||||
.execute(&*con)
|
||||
.execute(&con)
|
||||
.map_err(From::from)
|
||||
.map(|_| ())
|
||||
}
|
||||
@@ -69,7 +69,7 @@ impl Update for NewEpisode {
|
||||
info!("Updating {:?}", self.title);
|
||||
diesel::update(episode.filter(rowid.eq(episode_id)))
|
||||
.set(self)
|
||||
.execute(&*con)
|
||||
.execute(&con)
|
||||
.map_err(From::from)
|
||||
.map(|_| ())
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ impl Insert for NewPodcast {
|
||||
|
||||
diesel::insert_into(podcast)
|
||||
.values(self)
|
||||
.execute(&*con)
|
||||
.execute(&con)
|
||||
.map(|_| ())
|
||||
.map_err(From::from)
|
||||
}
|
||||
@@ -51,7 +51,7 @@ impl Update for NewPodcast {
|
||||
info!("Updating {}", self.title);
|
||||
diesel::update(podcast.filter(id.eq(podcast_id)))
|
||||
.set(self)
|
||||
.execute(&*con)
|
||||
.execute(&con)
|
||||
.map(|_| ())
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ impl Insert for NewSource {
|
||||
let con = db.get()?;
|
||||
|
||||
// FIXME: Insert or ignore
|
||||
let _ = diesel::insert_into(source).values(self).execute(&*con);
|
||||
let _ = diesel::insert_into(source).values(self).execute(&con);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use hyper::client::HttpConnector;
|
||||
use hyper::header::{ETag, EntityTag, HttpDate, IfModifiedSince, IfNoneMatch, LastModified};
|
||||
use hyper_tls::HttpsConnector;
|
||||
|
||||
use futures::future::ok;
|
||||
// use futures::future::ok;
|
||||
use futures::prelude::*;
|
||||
|
||||
use database::connection;
|
||||
@@ -71,7 +71,7 @@ impl Source {
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
Ok(self.save_changes::<Source>(&*con)?)
|
||||
Ok(self.save_changes::<Source>(&con)?)
|
||||
}
|
||||
|
||||
/// Extract Etag and LastModifier from res, and update self and the
|
||||
@@ -114,11 +114,11 @@ impl Source {
|
||||
let id = self.id();
|
||||
let feed = self.request_constructor(client, ignore_etags)
|
||||
.map_err(From::from)
|
||||
.and_then(move |res| -> Result<Response> {
|
||||
.and_then(move |res| {
|
||||
self.update_etag(&res)?;
|
||||
Ok(res)
|
||||
})
|
||||
.and_then(|res| -> Result<Response> {
|
||||
.and_then(|res| {
|
||||
match_status(res.status())?;
|
||||
Ok(res)
|
||||
})
|
||||
@@ -159,18 +159,18 @@ impl Source {
|
||||
}
|
||||
}
|
||||
|
||||
let work = client.request(req).map_err(From::from);
|
||||
let work = client.request(req);
|
||||
Box::new(work)
|
||||
}
|
||||
}
|
||||
|
||||
fn response_to_channel(res: Response) -> Box<Future<Item = Channel, Error = Error>> {
|
||||
fn response_to_channel(res: Response) -> Box<Future<Item = Channel, Error = Error> + Send> {
|
||||
let chan = res.body()
|
||||
.concat2()
|
||||
.map(|x| x.into_iter())
|
||||
.map_err(From::from)
|
||||
.and_then(|iter| ok(iter.collect::<Vec<u8>>()))
|
||||
.and_then(|utf_8_bytes| ok(String::from_utf8_lossy(&utf_8_bytes).into_owned()))
|
||||
.map(|iter| iter.collect::<Vec<u8>>())
|
||||
.map(|utf_8_bytes| String::from_utf8_lossy(&utf_8_bytes).into_owned())
|
||||
.and_then(|buf| Channel::from_str(&buf).map_err(From::from));
|
||||
|
||||
Box::new(chan)
|
||||
|
||||
Reference in New Issue
Block a user