Now Upon feed addition only that feed is indexed/updated.
This commit is contained in:
parent
753cdae08f
commit
486e0ff5e4
@ -88,7 +88,7 @@ pub fn index_loop(db: Arc<Mutex<SqliteConnection>>, force: bool) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_index_from_source(
|
pub fn complete_index_from_source(
|
||||||
req: &mut reqwest::Response,
|
req: &mut reqwest::Response,
|
||||||
source: &Source,
|
source: &Source,
|
||||||
mutex: Arc<Mutex<SqliteConnection>>,
|
mutex: Arc<Mutex<SqliteConnection>>,
|
||||||
@ -165,7 +165,7 @@ pub fn fetch_feeds(
|
|||||||
Ok(results)
|
Ok(results)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn refresh_source(
|
pub fn refresh_source(
|
||||||
connection: &SqliteConnection,
|
connection: &SqliteConnection,
|
||||||
feed: &mut Source,
|
feed: &mut Source,
|
||||||
force: bool,
|
force: bool,
|
||||||
@ -188,11 +188,11 @@ fn refresh_source(
|
|||||||
|
|
||||||
// FIXME: I have fucked up somewhere here.
|
// FIXME: I have fucked up somewhere here.
|
||||||
// Getting back 200 codes even though I supposedly sent etags.
|
// Getting back 200 codes even though I supposedly sent etags.
|
||||||
info!("Headers: {:?}", headers);
|
// info!("Headers: {:?}", headers);
|
||||||
client.get(feed.uri()).headers(headers).send()?
|
client.get(feed.uri()).headers(headers).send()?
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("{}", req.status());
|
info!("GET to {} , returned: {}", feed.uri(), req.status());
|
||||||
|
|
||||||
// TODO match on more stuff
|
// TODO match on more stuff
|
||||||
// 301: Permanent redirect of the url
|
// 301: Permanent redirect of the url
|
||||||
|
|||||||
@ -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);
|
let f = index_feed::insert_return_source(&tempdb, &url);
|
||||||
drop(tempdb);
|
drop(tempdb);
|
||||||
info!("{:?} feed added", url);
|
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!("Expected Error, feed probably already exists.");
|
||||||
error!("Error: {:?}", f.unwrap_err());
|
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: lock the button instead of hiding and add notification of feed added.
|
||||||
// TODO: map the spinner
|
// TODO: map the spinner
|
||||||
add_popover_clone.hide();
|
add_popover_clone.hide();
|
||||||
|
|||||||
@ -54,6 +54,8 @@ fn build_ui(app: >k::Application) {
|
|||||||
|
|
||||||
// Get the headerbar
|
// Get the headerbar
|
||||||
let header = headerbar::get_headerbar(db.clone(), stack.clone());
|
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.set_titlebar(&header);
|
||||||
|
|
||||||
window.show_all();
|
window.show_all();
|
||||||
|
|||||||
@ -4,6 +4,7 @@ use gtk;
|
|||||||
// use gtk::prelude::*;
|
// use gtk::prelude::*;
|
||||||
|
|
||||||
use hammond_data;
|
use hammond_data;
|
||||||
|
use hammond_data::models::Source;
|
||||||
use diesel::prelude::SqliteConnection;
|
use diesel::prelude::SqliteConnection;
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
@ -25,8 +26,34 @@ pub fn refresh_db(db: Arc<Mutex<SqliteConnection>>, stack: gtk::Stack) {
|
|||||||
handle.join();
|
handle.join();
|
||||||
|
|
||||||
podcasts_view::update_podcasts_view(db.clone(), stack.clone());
|
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.
|
// https://github.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user