App: Do not update the db if its empty
If the source table is empty skipp the database refresh.
This commit is contained in:
parent
5631caad36
commit
cc1a5783fd
@ -392,7 +392,7 @@ pub fn is_episodes_populated() -> Result<bool, DataError> {
|
|||||||
|
|
||||||
/// Check if the `shows` table contains any rows
|
/// 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> {
|
pub fn is_podcasts_populated(filter_ids: &[i32]) -> Result<bool, DataError> {
|
||||||
use schema::shows::dsl::*;
|
use schema::shows::dsl::*;
|
||||||
|
|
||||||
@ -404,6 +404,20 @@ pub fn is_podcasts_populated(filter_ids: &[i32]) -> Result<bool, DataError> {
|
|||||||
.map_err(From::from)
|
.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> {
|
pub(crate) fn index_new_episodes(eps: &[NewEpisode]) -> Result<(), DataError> {
|
||||||
use schema::episodes::dsl::*;
|
use schema::episodes::dsl::*;
|
||||||
let db = connection();
|
let db = connection();
|
||||||
|
|||||||
@ -187,6 +187,19 @@ pub(crate) fn refresh<S>(source: Option<S>, sender: Sender<Action>)
|
|||||||
where
|
where
|
||||||
S: IntoIterator<Item = Source> + Send + 'static,
|
S: IntoIterator<Item = Source> + Send + 'static,
|
||||||
{
|
{
|
||||||
|
// If we try to update the whole db,
|
||||||
|
// Exit early if `source` table is empty
|
||||||
|
if source.is_none() {
|
||||||
|
match dbqueries::is_source_populated(&[]) {
|
||||||
|
Ok(false) => {
|
||||||
|
info!("No source of feeds where found, returning");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Err(err) => debug_assert!(false, err),
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
refresh_feed(source, sender)
|
refresh_feed(source, sender)
|
||||||
.map_err(|err| error!("Failed to update feeds: {}", err))
|
.map_err(|err| error!("Failed to update feeds: {}", err))
|
||||||
.ok();
|
.ok();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user