Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 286773c9 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

RUST: Add a way to add things in the queue from the database connexion + fix...

RUST: Add a way to add things in the queue from the database connexion + fix the default insert function
parent 64948ce4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
use super::*; use super::{
queue::{LktDatabasePriority, LktDatabaseQueueRangeIter},
*,
};
use crate::{database::models::*, kurisu_api::v1 as api_v1}; use crate::{database::models::*, kurisu_api::v1 as api_v1};
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
...@@ -161,4 +163,39 @@ impl LktDatabaseConnection { ...@@ -161,4 +163,39 @@ impl LktDatabaseConnection {
}; };
Ok((id, kara, lang, kara_makers, tags)) 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)
}
} }
...@@ -10,7 +10,12 @@ pub mod unsafe_interface; ...@@ -10,7 +10,12 @@ pub mod unsafe_interface;
pub(self) use diesel::prelude::*; pub(self) use diesel::prelude::*;
pub(self) use error::*; pub(self) use error::*;
pub(self) use log::*; 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! /// All the information needed to add a kara recieved from a repo!
pub type NewKaraRequest<'a> = ( pub type NewKaraRequest<'a> = (
......
use std::{ use super::*;
collections::VecDeque,
ops::{Index, Range},
slice::SliceIndex,
};
/// The number of priority levels in the queues. The higher the number, the /// The number of priority levels in the queues. The higher the number, the
/// higher the priority. /// higher the priority.
...@@ -99,7 +95,7 @@ impl LktDatabaseQueue { ...@@ -99,7 +95,7 @@ impl LktDatabaseQueue {
} }
pub fn insert_kara(&mut self, local_id: u64) { 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) { pub fn insert_kara_with_priority(&mut self, local_id: u64, priority: LktDatabasePriority) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter