Use source_id as the unique identifieble field for the podcast table.

This commit is contained in:
Jordan Petridis
2017-11-25 01:56:10 +02:00
parent 12ffe5c231
commit 62da8bbb52
6 changed files with 65 additions and 45 deletions
+12 -2
View File
@@ -133,13 +133,23 @@ pub fn get_source_from_uri(uri_: &str) -> QueryResult<Source> {
source.filter(uri.eq(uri_)).get_result::<Source>(&*con)
}
pub fn get_podcast_from_title(title_: &str) -> QueryResult<Podcast> {
// pub fn get_podcast_from_title(title_: &str) -> QueryResult<Podcast> {
// use schema::podcast::dsl::*;
// let db = connection();
// let con = db.get().unwrap();
// podcast
// .filter(title.eq(title_))
// .get_result::<Podcast>(&*con)
// }
pub fn get_podcast_from_source_id(sid: i32) -> QueryResult<Podcast> {
use schema::podcast::dsl::*;
let db = connection();
let con = db.get().unwrap();
podcast
.filter(title.eq(title_))
.filter(source_id.eq(sid))
.get_result::<Podcast>(&*con)
}
+5 -3
View File
@@ -105,11 +105,11 @@ impl NewPodcast {
// Look out for when tryinto lands into stable.
pub fn into_podcast(self) -> Result<Podcast> {
self.index()?;
Ok(dbqueries::get_podcast_from_title(&self.title)?)
Ok(dbqueries::get_podcast_from_source_id(self.source_id)?)
}
pub fn index(&self) -> QueryResult<()> {
let pd = dbqueries::get_podcast_from_title(&self.title);
let pd = dbqueries::get_podcast_from_source_id(self.source_id);
let db = connection();
let con = db.get().unwrap();
@@ -119,7 +119,9 @@ impl NewPodcast {
error!("NPD sid: {}, PD sid: {}", self.source_id, foo.source_id());
};
if foo.link() != self.link {
if (foo.link() != self.link) || (foo.title() != self.title)
|| (foo.image_uri() != self.image_uri.as_ref().map(|x| x.as_str()))
{
dbqueries::replace_podcast(&con, self)?;
}
}