Now Upon feed addition only that feed is indexed/updated.

This commit is contained in:
Jordan Petridis 2017-10-21 00:12:24 +03:00
parent 753cdae08f
commit 486e0ff5e4
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
4 changed files with 39 additions and 11 deletions

View File

@ -88,7 +88,7 @@ pub fn index_loop(db: Arc<Mutex<SqliteConnection>>, force: bool) -> Result<()> {
Ok(())
}
fn complete_index_from_source(
pub fn complete_index_from_source(
req: &mut reqwest::Response,
source: &Source,
mutex: Arc<Mutex<SqliteConnection>>,
@ -165,7 +165,7 @@ pub fn fetch_feeds(
Ok(results)
}
fn refresh_source(
pub fn refresh_source(
connection: &SqliteConnection,
feed: &mut Source,
force: bool,
@ -188,11 +188,11 @@ fn refresh_source(
// FIXME: I have fucked up somewhere here.
// Getting back 200 codes even though I supposedly sent etags.
info!("Headers: {:?}", headers);
// info!("Headers: {:?}", headers);
client.get(feed.uri()).headers(headers).send()?
};
info!("{}", req.status());
info!("GET to {} , returned: {}", feed.uri(), req.status());
// TODO match on more stuff
// 301: Permanent redirect of the url

View File

@ -36,15 +36,14 @@ pub fn get_headerbar(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) -> gtk
let f = index_feed::insert_return_source(&tempdb, &url);
drop(tempdb);
info!("{:?} feed added", url);
if f.is_err() {
if let Ok(mut source) = f {
// update the db
utils::refresh_feed(db_clone.clone(), stack_clone.clone(), &mut source);
} else {
error!("Expected Error, feed probably already exists.");
error!("Error: {:?}", f.unwrap_err());
}
// update the db
// TODO: have it fettch only the added feed.
utils::refresh_db(db_clone.clone(), stack_clone.clone());
// TODO: lock the button instead of hiding and add notification of feed added.
// TODO: map the spinner
add_popover_clone.hide();

View File

@ -54,6 +54,8 @@ fn build_ui(app: &gtk::Application) {
// Get the headerbar
let header = headerbar::get_headerbar(db.clone(), stack.clone());
// Uncomment this when etag implementation is fixed and refesh_db thread is non blocking.
// utils::refresh_db(db.clone(), stack.clone());
window.set_titlebar(&header);
window.show_all();

View File

@ -4,6 +4,7 @@ use gtk;
// use gtk::prelude::*;
use hammond_data;
use hammond_data::models::Source;
use diesel::prelude::SqliteConnection;
use std::thread;
@ -25,8 +26,34 @@ pub fn refresh_db(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
handle.join();
podcasts_view::update_podcasts_view(db.clone(), stack.clone());
// let foo = stack.emit("foo", &[]);
// info!("{:?}", foo)
}
pub fn refresh_feed(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack, source: &mut Source) {
let db_clone = db.clone();
let source_ = source.clone();
// TODO: add timeout option and error reporting.
let handle = thread::spawn(move || {
let db_ = db_clone.lock().unwrap();
let foo = hammond_data::index_feed::refresh_source(&db_, &mut source_.clone(), false);
drop(db_);
if let Ok((mut req, s)) = foo {
let s = hammond_data::index_feed::complete_index_from_source(
&mut req,
&s,
db_clone.clone(),
);
if s.is_err() {
error!("Error While trying to update the database.");
error!("Error msg: {}", s.unwrap_err());
};
};
});
// FIXME: atm freezing the ui till update is done.
// Make it instead emmit a signal on update completion.
handle.join();
podcasts_view::update_podcasts_view(db.clone(), stack.clone());
}
// https://github.