mirror of
https://github.com/agersant/polaris
synced 2024-11-10 10:14:12 +00:00
Configurable re-index period
This commit is contained in:
parent
6268202e6d
commit
05e646a640
4 changed files with 43 additions and 7 deletions
|
@ -4,6 +4,9 @@ auth_secret = 'Something very secret'
|
|||
# Pattern used to match album art matching a file
|
||||
album_art_pattern = '^Folder\.(png|jpg|jpeg)$'
|
||||
|
||||
# How often the library should be re-indexed (in seconds)
|
||||
reindex_every_n_seconds = 43200
|
||||
|
||||
# Directories where your music is stored
|
||||
[[mount_dirs]]
|
||||
source = 'C:/Users/your_name/Music' # Location of the directory on your computer
|
||||
|
|
|
@ -7,6 +7,7 @@ use toml;
|
|||
|
||||
use collection::User;
|
||||
use ddns::DDNSConfig;
|
||||
use index::IndexConfig;
|
||||
use vfs::VfsConfig;
|
||||
|
||||
const CONFIG_SECRET: &'static str = "auth_secret";
|
||||
|
@ -17,6 +18,7 @@ const CONFIG_USERS: &'static str = "users";
|
|||
const CONFIG_USER_NAME: &'static str = "name";
|
||||
const CONFIG_USER_PASSWORD: &'static str = "password";
|
||||
const CONFIG_ALBUM_ART_PATTERN: &'static str = "album_art_pattern";
|
||||
const CONFIG_INDEX_SLEEP_DURATION: &'static str = "reindex_every_n_seconds";
|
||||
const CONFIG_DDNS: &'static str = "ydns";
|
||||
const CONFIG_DDNS_HOST: &'static str = "host";
|
||||
const CONFIG_DDNS_USERNAME: &'static str = "username";
|
||||
|
@ -28,6 +30,7 @@ pub enum ConfigError {
|
|||
TOMLParseError,
|
||||
RegexError(regex::Error),
|
||||
SecretParseError,
|
||||
SleepDurationParseError,
|
||||
AlbumArtPatternParseError,
|
||||
UsersParseError,
|
||||
MountDirsParseError,
|
||||
|
@ -51,7 +54,7 @@ pub struct Config {
|
|||
pub secret: String,
|
||||
pub vfs: VfsConfig,
|
||||
pub users: Vec<User>,
|
||||
pub album_art_pattern: Option<regex::Regex>,
|
||||
pub index: IndexConfig,
|
||||
pub ddns: Option<DDNSConfig>,
|
||||
}
|
||||
|
||||
|
@ -67,11 +70,12 @@ impl Config {
|
|||
secret: String::new(),
|
||||
vfs: VfsConfig::new(),
|
||||
users: Vec::new(),
|
||||
album_art_pattern: None,
|
||||
index: IndexConfig::new(),
|
||||
ddns: None,
|
||||
};
|
||||
|
||||
try!(config.parse_secret(&parsed_config));
|
||||
try!(config.parse_index_sleep_duration(&parsed_config));
|
||||
try!(config.parse_mount_points(&parsed_config));
|
||||
try!(config.parse_users(&parsed_config));
|
||||
try!(config.parse_album_art_pattern(&parsed_config));
|
||||
|
@ -87,6 +91,19 @@ impl Config {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_index_sleep_duration(&mut self, source: &toml::Table) -> Result<(), ConfigError> {
|
||||
let sleep_duration = match source.get(CONFIG_INDEX_SLEEP_DURATION) {
|
||||
Some(s) => s,
|
||||
None => return Ok(()),
|
||||
};
|
||||
let sleep_duration = match sleep_duration {
|
||||
&toml::Value::Integer(s) => s as u64,
|
||||
_ => return Err(ConfigError::SleepDurationParseError),
|
||||
};
|
||||
self.index.sleep_duration = sleep_duration;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_album_art_pattern(&mut self, source: &toml::Table) -> Result<(), ConfigError> {
|
||||
let pattern = match source.get(CONFIG_ALBUM_ART_PATTERN) {
|
||||
Some(s) => s,
|
||||
|
@ -96,7 +113,7 @@ impl Config {
|
|||
&toml::Value::String(ref s) => s,
|
||||
_ => return Err(ConfigError::AlbumArtPatternParseError),
|
||||
};
|
||||
self.album_art_pattern = Some(try!(regex::Regex::new(pattern)));
|
||||
self.index.album_art_pattern = Some(try!(regex::Regex::new(pattern)));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
22
src/index.rs
22
src/index.rs
|
@ -18,10 +18,25 @@ use vfs::Vfs;
|
|||
const INDEX_BUILDING_INSERT_BUFFER_SIZE: usize = 250; // Insertions in each transaction
|
||||
const INDEX_LOCK_TIMEOUT: usize = 1000; // In milliseconds
|
||||
|
||||
pub struct IndexConfig {
|
||||
pub album_art_pattern: Option<Regex>,
|
||||
pub sleep_duration: u64, // in seconds
|
||||
}
|
||||
|
||||
impl IndexConfig {
|
||||
pub fn new() -> IndexConfig {
|
||||
IndexConfig {
|
||||
sleep_duration: 60 * 30, // 30 minutes
|
||||
album_art_pattern: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Index {
|
||||
path: String,
|
||||
vfs: Arc<Vfs>,
|
||||
album_art_pattern: Option<Regex>,
|
||||
sleep_duration: u64,
|
||||
}
|
||||
|
||||
struct SongTags {
|
||||
|
@ -257,13 +272,14 @@ impl<'db> Drop for IndexBuilder<'db> {
|
|||
impl Index {
|
||||
pub fn new(path: &Path,
|
||||
vfs: Arc<Vfs>,
|
||||
album_art_pattern: &Option<Regex>)
|
||||
config: &IndexConfig)
|
||||
-> Result<Index, PError> {
|
||||
|
||||
let index = Index {
|
||||
path: path.to_string_lossy().deref().to_string(),
|
||||
vfs: vfs,
|
||||
album_art_pattern: album_art_pattern.clone(),
|
||||
album_art_pattern: config.album_art_pattern.clone(),
|
||||
sleep_duration: config.sleep_duration,
|
||||
};
|
||||
|
||||
if path.exists() {
|
||||
|
@ -500,7 +516,7 @@ impl Index {
|
|||
let db = self.connect();
|
||||
self.update_index(&db);
|
||||
}
|
||||
thread::sleep(time::Duration::from_secs(60 * 20)); // TODO expose in configuration
|
||||
thread::sleep(time::Duration::from_secs(self.sleep_duration));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ fn main() {
|
|||
// Init index
|
||||
println!("Starting up index");
|
||||
let index_path = path::Path::new(INDEX_FILE_NAME);
|
||||
let index = Arc::new(index::Index::new(&index_path, vfs.clone(), &config.album_art_pattern)
|
||||
let index = Arc::new(index::Index::new(&index_path, vfs.clone(), &config.index)
|
||||
.unwrap());
|
||||
let index_ref = index.clone();
|
||||
std::thread::spawn(move || index_ref.run());
|
||||
|
|
Loading…
Reference in a new issue