diff --git a/src/rust/liblektor-rs/src/database/connexion.rs b/src/rust/liblektor-rs/src/database/connexion.rs index e3619b598a24941116c3ed6493953550ecb1cdcd..0443ade497069a159e3c636fd832a2ffd2f2e275 100644 --- a/src/rust/liblektor-rs/src/database/connexion.rs +++ b/src/rust/liblektor-rs/src/database/connexion.rs @@ -1,5 +1,7 @@ -use super::*; - +use super::{ + queue::{LktDatabasePriority, LktDatabaseQueueRangeIter}, + *, +}; use crate::{database::models::*, kurisu_api::v1 as api_v1}; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; @@ -161,4 +163,39 @@ impl LktDatabaseConnection { }; Ok((id, kara, lang, kara_makers, tags)) } + + /// Peek the next kara to play + pub fn peek_next_kara_in_queue(&self) -> Option<u64> { + self.queue.peek_next() + } + + /// Pop the next kara to play + pub fn pop_next_kara_in_queue(&mut self) -> Option<u64> { + self.queue.pop_next() + } + + /// Get the content of the queue from a range. + pub fn get_queue_content(&self, range: Range<usize>) -> LktDatabaseQueueRangeIter { + self.queue.range(range) + } + + /// Add a kara at the end of the queue. + pub fn enqueue_kara(&mut self, local_id: u64) { + self.queue.enqueue_kara(local_id) + } + + /// Add a kara at the end of a priority in the queue. + pub fn enqueue_kara_with_priority(&mut self, local_id: u64, priority: LktDatabasePriority) { + self.queue.enqueue_kara_with_priority(local_id, priority) + } + + /// Add a kara at the top of the queue. + pub fn insert_kara(&mut self, local_id: u64) { + self.queue.insert_kara(local_id) + } + + /// Add a kara at the top of a priority in the queue. + pub fn insert_kara_with_priority(&mut self, local_id: u64, priority: LktDatabasePriority) { + self.queue.insert_kara_with_priority(local_id, priority) + } } diff --git a/src/rust/liblektor-rs/src/database/mod.rs b/src/rust/liblektor-rs/src/database/mod.rs index 159cbedd19e0c27be62fcffa7dc05d81d895f1a4..5360847921a2f92449fde49ab8f5ec8e448f3f1c 100644 --- a/src/rust/liblektor-rs/src/database/mod.rs +++ b/src/rust/liblektor-rs/src/database/mod.rs @@ -10,7 +10,12 @@ pub mod unsafe_interface; pub(self) use diesel::prelude::*; pub(self) use error::*; pub(self) use log::*; -pub(self) use std::path::Path; +pub(self) use std::{ + collections::VecDeque, + ops::{Index, Range}, + path::Path, + slice::SliceIndex, +}; /// All the information needed to add a kara recieved from a repo! pub type NewKaraRequest<'a> = ( diff --git a/src/rust/liblektor-rs/src/database/queue.rs b/src/rust/liblektor-rs/src/database/queue.rs index 10e4054124240cb2b6f7fde845d459acbda72ab3..8be40e49a5d8aa263ec459e709c5c19a363728a8 100644 --- a/src/rust/liblektor-rs/src/database/queue.rs +++ b/src/rust/liblektor-rs/src/database/queue.rs @@ -1,8 +1,4 @@ -use std::{ - collections::VecDeque, - ops::{Index, Range}, - slice::SliceIndex, -}; +use super::*; /// The number of priority levels in the queues. The higher the number, the /// higher the priority. @@ -99,7 +95,7 @@ impl LktDatabaseQueue { } pub fn insert_kara(&mut self, local_id: u64) { - self.levels[0].push_front(local_id); + self.levels[LKT_DATABASE_QUEUES_COUNT - 1].push_front(local_id); } pub fn insert_kara_with_priority(&mut self, local_id: u64, priority: LktDatabasePriority) {