Spawn a separate thread to update the db and dont freeze the gui.

This commit is contained in:
Jordan Petridis 2017-10-18 02:34:59 +03:00
parent 4d77fa47d8
commit e3c1464a67
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6

View File

@ -15,7 +15,9 @@ extern crate loggerv;
use log::LogLevel; use log::LogLevel;
use diesel::prelude::*; use diesel::prelude::*;
use hammond_data::dbqueries; use hammond_data::dbqueries;
use std::rc; use std::rc;
use std::thread;
use gtk::prelude::*; use gtk::prelude::*;
use gio::ApplicationExt; use gio::ApplicationExt;
@ -209,12 +211,13 @@ fn build_ui() {
home_button.connect_clicked(move |_| stack_clone.set_visible_child(&grid_clone)); home_button.connect_clicked(move |_| stack_clone.set_visible_child(&grid_clone));
let refresh_button: gtk::Button = header_build.get_object("refbutton").unwrap(); let refresh_button: gtk::Button = header_build.get_object("refbutton").unwrap();
// FIXME: This locks the ui atm. // FIXME: There appears to be a memmory leak here.
// FIXME: it also leaks memmory.
refresh_button.connect_clicked(move |_| { refresh_button.connect_clicked(move |_| {
thread::spawn(|| {
let db = hammond_data::establish_connection(); let db = hammond_data::establish_connection();
hammond_data::index_feed::index_loop(db, false).unwrap(); hammond_data::index_feed::index_loop(db, false).unwrap();
}); });
});
// let pd_model = create_and_fill_tree_store(&db, &builder); // let pd_model = create_and_fill_tree_store(&db, &builder);
let pd_model = create_and_fill_list_store(&db, &builder); let pd_model = create_and_fill_list_store(&db, &builder);