Upgrade Diesel to 1.1
This commit is contained in:
parent
20f36a67a0
commit
66e816fc5f
47
Cargo.lock
generated
47
Cargo.lock
generated
@ -294,17 +294,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "diesel"
|
||||
version = "1.0.0"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel_derives 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel_derives 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libsqlite3-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diesel_derives"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -313,11 +314,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "diesel_migrations"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"migrations_internals 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"migrations_macros 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"migrations_internals 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"migrations_macros 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -612,8 +613,8 @@ dependencies = [
|
||||
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"criterion 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"derive_builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel_migrations 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel_migrations 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dotenv 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -623,8 +624,6 @@ dependencies = [
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"native-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"reqwest 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -931,18 +930,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "migrations_internals"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "migrations_macros"
|
||||
version = "1.0.0"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"migrations_internals 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"migrations_internals 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -1214,15 +1213,6 @@ dependencies = [
|
||||
"scheduled-thread-pool 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r2d2-diesel"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.3.20"
|
||||
@ -1881,9 +1871,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum derive-error-chain 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9ca9ade651388daad7c993f005d0d20c4f6fe78c1cdc93e95f161c6f5ede4a"
|
||||
"checksum derive_builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c998e6ab02a828dd9735c18f154e14100e674ed08cb4e1938f0e4177543f439"
|
||||
"checksum derive_builder_core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "735e24ee9e5fa8e16b86da5007856e97d592e11867e45d76e0c0d0a164a0b757"
|
||||
"checksum diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de51f2e2321a7db9bdfd7e3457c6ce11dce5009cad7ff9ac25a04879239e5fe6"
|
||||
"checksum diesel_derives 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "274aeed033dcd9e40f472cd282a3692512fef153283ec4c745873517d0e67f3f"
|
||||
"checksum diesel_migrations 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45efc922686673614d4aee6ddd47ebef2d5c789a0a0b34e0df5efaaedac51d09"
|
||||
"checksum diesel 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925325c57038f2f14c0413bdf6a92ca72acff644959d0a1a9ebf8d19be7e9c01"
|
||||
"checksum diesel_derives 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "28e2b2605ac6a3b9a586383f5f8b2b5f1108f07a421ade965b266289d2805e79"
|
||||
"checksum diesel_migrations 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0928a7d6f27c849954185416bd59439837de55fbc89e2985b0e46e756ae4e3da"
|
||||
"checksum dissolve 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "898542be4716d992082c8e4fc331b792d626cfa71cb2b4790f828b9a8f921a90"
|
||||
"checksum dotenv 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d6f0e2bb24d163428d8031d3ebd2d2bd903ad933205a97d0f18c7c1aade380f3"
|
||||
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
|
||||
@ -1942,8 +1932,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum markup5ever 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c220b3a3d75543b76e5c1fcab6635a8430ab5f9bfa011d003c3787ae0abf4ffa"
|
||||
"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376"
|
||||
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
|
||||
"checksum migrations_internals 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd5248cbbe4f45d5b4e6cf13a9f37aa587d31c41d2d8b80a0bf0aaf2e30c862d"
|
||||
"checksum migrations_macros 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06b25945741aeb3a00bb37eb142d03480e96230fff5569327ab4ac2082449df2"
|
||||
"checksum migrations_internals 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd916de6df9ac7e811e7e1ac28e0abfebe5205f3b29a7bda9ec8a41ee980a4eb"
|
||||
"checksum migrations_macros 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5a550cfd76f6cfdf15a7b541893d7c79b68277b0b309f12179211a373a56e617"
|
||||
"checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
|
||||
"checksum mime 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e00e17be181010a91dbfefb01660b17311059dc8c7f48b9017677721e732bd"
|
||||
"checksum mime_guess 1.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dc7e82a15629bb4ecd9e72365bf33d1382be91e030f820edb8e2a21c02430da8"
|
||||
@ -1973,7 +1963,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum quick-xml 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "19602854dba17f93b3011fe272af6db3133d5b495279f504bf9104dc97879717"
|
||||
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
|
||||
"checksum r2d2 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f9078ca6a8a5568ed142083bb2f7dc9295b69d16f867ddcc9849e51b17d8db46"
|
||||
"checksum r2d2-diesel 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9c29bad92da76d02bc2c020452ebc3a3fe6fa74cfab91e711c43116e4fb1a3"
|
||||
"checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1"
|
||||
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
|
||||
"checksum rayon 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed02d09394c94ffbdfdc755ad62a132e94c3224a8354e78a1200ced34df12edf"
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user