In place update a podcast row instead of replace.

This commit is contained in:
Jordan Petridis 2017-11-25 18:22:56 +02:00
parent f83f894e44
commit 2f801043c1
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 14 additions and 4 deletions

3
.gitignore vendored
View File

@ -7,6 +7,7 @@ Cargo.lock
_build
vendor/
.flatpak-builder/
flatpak-build/
flatpak-repo/
repo/
Makefile
hammond-repo/

View File

@ -235,3 +235,10 @@ pub fn replace_episode(con: &SqliteConnection, ep: &NewEpisode) -> QueryResult<u
diesel::replace_into(episode).values(ep).execute(&*con)
}
pub fn update_podcast(con: &SqliteConnection, pd_id: i32, pd: &NewPodcast) -> QueryResult<usize> {
use schema::podcast::dsl::*;
diesel::update(podcast.filter(id.eq(pd_id)))
.set(pd)
.execute(&*con)
}

View File

@ -2,6 +2,7 @@ use diesel::prelude::*;
use schema::{episode, podcast, source};
use models::{Episode, Podcast, Source};
use utils::url_cleaner;
use errors::*;
@ -79,6 +80,7 @@ impl NewEpisode {
if foo.title() != self.title.as_ref().map(|x| x.as_str())
|| foo.published_date() != self.published_date.as_ref().map(|x| x.as_str())
{
// TODO: Update instead of replace
dbqueries::replace_episode(con, self)?;
}
}
@ -90,7 +92,7 @@ impl NewEpisode {
}
}
#[derive(Insertable)]
#[derive(Insertable, AsChangeset)]
#[table_name = "podcast"]
#[derive(Debug, Clone)]
pub struct NewPodcast {
@ -116,13 +118,13 @@ impl NewPodcast {
match pd {
Ok(foo) => {
if foo.source_id() != self.source_id {
error!("NPD sid: {}, PD sid: {}", self.source_id, foo.source_id());
error!("NSPD sid: {}, SPD sid: {}", self.source_id, foo.source_id());
};
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)?;
dbqueries::update_podcast(&con, *foo.id(), self)?;
}
}
Err(_) => {