forked from didirus/AstralRinth
* Support for using a master key * Expand scope of PR, add wrapper struct, add files to intitial versions/mods * Change changelog path, run formatter * Split file changes into different PR * Formatting, rename main variable Co-authored-by: Aeledfyr <aeledfyr@gmail.com>
36 lines
1.0 KiB
Rust
36 lines
1.0 KiB
Rust
use super::{add_mods, IndexingError, UploadSearchMod};
|
|
use crate::search::SearchConfig;
|
|
use std::sync::Mutex;
|
|
|
|
pub struct CreationQueue {
|
|
// There's probably a better structure for this, but a mutex works
|
|
// and I don't think this can deadlock. This queue requires fast
|
|
// writes and then a single potentially slower read/write that
|
|
// empties the queue.
|
|
queue: Mutex<Vec<UploadSearchMod>>,
|
|
}
|
|
|
|
impl CreationQueue {
|
|
pub fn new() -> Self {
|
|
CreationQueue {
|
|
queue: Mutex::new(Vec::with_capacity(10)),
|
|
}
|
|
}
|
|
|
|
pub fn add(&self, search_mod: UploadSearchMod) {
|
|
// Can only panic if mutex is poisoned
|
|
self.queue.lock().unwrap().push(search_mod);
|
|
}
|
|
pub fn take(&self) -> Vec<UploadSearchMod> {
|
|
std::mem::replace(&mut *self.queue.lock().unwrap(), Vec::with_capacity(10))
|
|
}
|
|
}
|
|
|
|
pub async fn index_queue(
|
|
queue: &CreationQueue,
|
|
config: &SearchConfig,
|
|
) -> Result<(), IndexingError> {
|
|
let queue = queue.take();
|
|
add_mods(queue, config).await
|
|
}
|