Added limit option for dbquerries::latest_dl.
This commit is contained in:
parent
fc693a569b
commit
d5c4b13b4d
@ -21,7 +21,7 @@ pub fn run() -> Result<()> {
|
||||
|
||||
::init()?;
|
||||
let db = ::establish_connection();
|
||||
downloader::latest_dl(&db)?;
|
||||
downloader::latest_dl(&db, 2)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -37,7 +37,25 @@ pub fn get_podcast(con: &SqliteConnection, parent: &Source) -> QueryResult<Vec<P
|
||||
}
|
||||
|
||||
pub fn get_pd_episodes(con: &SqliteConnection, parent: &Podcast) -> QueryResult<Vec<Episode>> {
|
||||
let eps = Episode::belonging_to(parent).load::<Episode>(con);
|
||||
use schema::episode::dsl::*;
|
||||
|
||||
let eps = Episode::belonging_to(parent)
|
||||
.order(epoch.desc())
|
||||
.load::<Episode>(con);
|
||||
eps
|
||||
}
|
||||
|
||||
pub fn get_pd_episodes_limit(
|
||||
con: &SqliteConnection,
|
||||
parent: &Podcast,
|
||||
limit: u32,
|
||||
) -> QueryResult<Vec<Episode>> {
|
||||
use schema::episode::dsl::*;
|
||||
|
||||
let eps = Episode::belonging_to(parent)
|
||||
.order(epoch.desc())
|
||||
.limit(limit as i64)
|
||||
.load::<Episode>(con);
|
||||
eps
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ use reqwest;
|
||||
use hyper::header::*;
|
||||
use diesel::prelude::*;
|
||||
|
||||
use std::fs::{File, DirBuilder};
|
||||
use std::fs::{DirBuilder, File};
|
||||
use std::io::{BufWriter, Read, Write};
|
||||
|
||||
use errors::*;
|
||||
@ -48,12 +48,17 @@ pub fn download_to(target: &str, url: &str) -> Result<()> {
|
||||
}
|
||||
|
||||
// Initial messy prototype, queries load alot of not needed stuff.
|
||||
pub fn latest_dl(connection: &SqliteConnection) -> Result<()> {
|
||||
pub fn latest_dl(connection: &SqliteConnection, limit: u32) -> Result<()> {
|
||||
let pds = dbqueries::get_podcasts(connection)?;
|
||||
|
||||
|
||||
pds.iter()
|
||||
.map(|x| -> Result<()> {
|
||||
let eps = dbqueries::get_pd_episodes(connection, &x)?;
|
||||
let eps;
|
||||
if limit == 0 {
|
||||
eps = dbqueries::get_pd_episodes(connection, &x)?;
|
||||
} else {
|
||||
eps = dbqueries::get_pd_episodes_limit(connection, &x, limit)?;
|
||||
}
|
||||
|
||||
// It might be better to make it a hash of the title
|
||||
let dl_fold = format!("{}/{}", ::DL_DIR.to_str().unwrap(), x.title());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user