Less coupling between DB and Index

This commit is contained in:
Antoine Gersant 2017-07-01 13:30:31 -07:00
parent 8a7a63ce61
commit f498956710
3 changed files with 6 additions and 15 deletions

View file

@ -8,7 +8,6 @@ use std::sync::{Arc, Mutex};
use config::{MiscSettings, UserConfig};
use errors::*;
use index;
use user::*;
mod schema;
@ -108,14 +107,6 @@ impl DB {
let misc: MiscSettings = misc_settings::table.get_result(connection)?;
Ok(misc.auth_secret.to_owned())
}
pub fn index_update(&self) -> Result<()> {
index::update(self)
}
pub fn index_update_loop(&self) {
index::update_loop(self);
}
}
impl ConnectionSource for DB {

View file

@ -619,7 +619,7 @@ fn test_browse_top_level() {
root_path.push("root");
let db = _get_test_db("browse_top_level.sqlite");
db.index_update().unwrap();
update(&db).unwrap();
let results = browse(&db, Path::new("")).unwrap();
assert_eq!(results.len(), 1);
@ -640,7 +640,7 @@ fn test_browse() {
tobokegao_path.push("Tobokegao");
let db = _get_test_db("browse.sqlite");
db.index_update().unwrap();
update(&db).unwrap();
let results = browse(&db, Path::new("root")).unwrap();
assert_eq!(results.len(), 2);
@ -657,7 +657,7 @@ fn test_browse() {
#[test]
fn test_flatten() {
let db = _get_test_db("flatten.sqlite");
db.index_update().unwrap();
update(&db).unwrap();
let results = flatten(&db, Path::new("root")).unwrap();
assert_eq!(results.len(), 12);
}
@ -665,7 +665,7 @@ fn test_flatten() {
#[test]
fn test_random() {
let db = _get_test_db("random.sqlite");
db.index_update().unwrap();
update(&db).unwrap();
let results = get_random_albums(&db, 1).unwrap();
assert_eq!(results.len(), 1);
}
@ -673,7 +673,7 @@ fn test_random() {
#[test]
fn test_recent() {
let db = _get_test_db("recent.sqlite");
db.index_update().unwrap();
update(&db).unwrap();
let results = get_recent_albums(&db, 2).unwrap();
assert_eq!(results.len(), 2);
assert!(results[0].date_added >= results[1].date_added);

View file

@ -126,7 +126,7 @@ fn run() -> Result<()> {
let db_ref = db.clone();
std::thread::spawn(move || {
let db = db_ref.deref();
db.index_update_loop();
index::update_loop(db);
});
// Mount API