Renamed watched field in the episode table of the database to played.

This commit is contained in:
Jordan Petridis
2017-10-30 14:13:36 +02:00
parent 25344aa613
commit faf4a4bce0
6 changed files with 27 additions and 27 deletions
+8 -8
View File
@@ -32,18 +32,18 @@ fn download_checker(db: &Database) -> Result<()> {
}
// TODO: Write unit test.
fn watched_cleaner(db: &Database) -> Result<()> {
fn played_cleaner(db: &Database) -> Result<()> {
let mut episodes = {
let tempdb = db.lock().unwrap();
dbqueries::get_watched_episodes(&tempdb)?
dbqueries::get_played_episodes(&tempdb)?
};
let now_utc = Utc::now().timestamp() as i32;
episodes.par_iter_mut().for_each(|mut ep| {
if ep.local_uri().is_some() && ep.watched().is_some() {
let watched = ep.watched().unwrap();
if ep.local_uri().is_some() && ep.played().is_some() {
let played = ep.played().unwrap();
// TODO: expose a config and a user set option.
let limit = watched + 172_800; // add 2days in seconds
let limit = played + 172_800; // add 2days in seconds
if now_utc > limit {
let e = delete_local_content(&Arc::clone(db), &mut ep);
if let Err(err) = e {
@@ -79,15 +79,15 @@ pub fn delete_local_content(db: &Database, ep: &mut Episode) -> Result<()> {
Ok(())
}
pub fn set_watched_now(db: &Database, ep: &mut Episode) -> Result<()> {
pub fn set_played_now(db: &Database, ep: &mut Episode) -> Result<()> {
let epoch = Utc::now().timestamp() as i32;
ep.set_watched(Some(epoch));
ep.set_played(Some(epoch));
ep.save(db)?;
Ok(())
}
pub fn run(db: &Database) -> Result<()> {
download_checker(db)?;
watched_cleaner(db)?;
played_cleaner(db)?;
Ok(())
}
+5 -5
View File
@@ -45,10 +45,10 @@ pub fn get_downloaded_episodes(con: &SqliteConnection) -> QueryResult<Vec<Episod
eps
}
pub fn get_watched_episodes(con: &SqliteConnection) -> QueryResult<Vec<Episode>> {
pub fn get_played_episodes(con: &SqliteConnection) -> QueryResult<Vec<Episode>> {
use schema::episode::dsl::*;
let eps = episode.filter(watched.is_not_null()).load::<Episode>(con);
let eps = episode.filter(played.is_not_null()).load::<Episode>(con);
eps
}
@@ -104,7 +104,7 @@ pub fn get_pd_unplayed_episodes(
use schema::episode::dsl::*;
let eps = Episode::belonging_to(parent)
.filter(watched.is_null())
.filter(played.is_null())
.order(epoch.desc())
.load::<Episode>(con);
eps
@@ -185,8 +185,8 @@ pub fn update_none_to_played_now(connection: &SqliteConnection, parent: &Podcast
use schema::episode::dsl::*;
let epoch_now = Utc::now().timestamp() as i32;
diesel::update(Episode::belonging_to(parent).filter(watched.is_null()))
.set(watched.eq(Some(epoch_now)))
diesel::update(Episode::belonging_to(parent).filter(played.is_null()))
.set(played.eq(Some(epoch_now)))
.execute(connection)?;
Ok(())
+6 -6
View File
@@ -22,8 +22,8 @@ pub struct Episode {
epoch: i32,
length: Option<i32>,
guid: Option<String>,
/// Represent the epoch value of when the episode was last watched.
watched: Option<i32>,
/// Represent the epoch value of when the episode was last played.
played: Option<i32>,
podcast_id: i32,
}
@@ -97,12 +97,12 @@ impl Episode {
self.length = value;
}
pub fn watched(&self) -> Option<i32> {
self.watched
pub fn played(&self) -> Option<i32> {
self.played
}
pub fn set_watched(&mut self, value: Option<i32>) {
self.watched = value;
pub fn set_played(&mut self, value: Option<i32>) {
self.played = value;
}
pub fn save(&self, db: &Database) -> Result<()> {
+1 -1
View File
@@ -9,7 +9,7 @@ table! {
epoch -> Integer,
length -> Nullable<Integer>,
guid -> Nullable<Text>,
watched -> Nullable<Integer>,
played -> Nullable<Integer>,
podcast_id -> Integer,
}
}