App: Do not update the db if its empty

If the source table is empty skipp the database refresh.
This commit is contained in:
Jordan Petridis
2018-08-14 15:19:31 +03:00
parent 5631caad36
commit cc1a5783fd
2 changed files with 28 additions and 1 deletions
+15 -1
View File
@@ -392,7 +392,7 @@ pub fn is_episodes_populated() -> Result<bool, DataError> {
/// Check if the `shows` table contains any rows
///
/// Return true if `shows table is populated.
/// Return true if `shows` table is populated.
pub fn is_podcasts_populated(filter_ids: &[i32]) -> Result<bool, DataError> {
use schema::shows::dsl::*;
@@ -404,6 +404,20 @@ pub fn is_podcasts_populated(filter_ids: &[i32]) -> Result<bool, DataError> {
.map_err(From::from)
}
/// Check if the `source` table contains any rows
///
/// Return true if `source` table is populated.
pub fn is_source_populated(filter_ids: &[i32]) -> Result<bool, DataError> {
use schema::source::dsl::*;
let db = connection();
let con = db.get()?;
select(exists(source.filter(id.ne_all(filter_ids))))
.get_result(&con)
.map_err(From::from)
}
pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<(), DataError> {
use schema::episodes::dsl::*;
let db = connection();