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

WIP: We will load and write patch files for the database with auxiliary types.

parent 47f14a3f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -9,17 +9,15 @@ use lru::LruCache; ...@@ -9,17 +9,15 @@ use lru::LruCache;
/// cache, if its the playlists that are updated, we clear only the playlist, if /// cache, if its the playlists that are updated, we clear only the playlist, if
/// it's the database, we clear everything. /// it's the database, we clear everything.
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug)]
pub struct AmaDB { pub struct AmaDB {
/// Cache requests to lektord and patched karas. The first element is the /// Cache requests to lektord and patched karas. The first element is the
/// lektord entry, the second one is the patched version. /// lektord entry, the second one is the patched version.
/// TODO: Find a structure that does COW to not duplicate too much /// TODO: Find a structure that does COW to not duplicate too much
/// information in the patched version... /// information in the patched version...
#[serde(skip, default = "new_empty_kara_lru")]
karas: LruCache<i64, (KaraInfo, Option<KaraInfo>)>, karas: LruCache<i64, (KaraInfo, Option<KaraInfo>)>,
/// The playlists. We don't save them... /// The playlists. We don't save them...
#[serde(skip, default = "new_empty_playlist_lru")]
playlists: LruCache<SmallString, Playlist>, playlists: LruCache<SmallString, Playlist>,
/// The list of overrides, indexed by the local id of the kara. /// The list of overrides, indexed by the local id of the kara.
...@@ -56,6 +54,9 @@ fn new_empty_playlist_lru() -> LruCache<SmallString, Playlist> { ...@@ -56,6 +54,9 @@ fn new_empty_playlist_lru() -> LruCache<SmallString, Playlist> {
} }
impl AmaDB { impl AmaDB {
/// Create a new empty [AmaDB].
pub fn new() -> Self {}
/// Clear the database cache, and only the caches about karas. /// Clear the database cache, and only the caches about karas.
pub fn clear_database_cache(&mut self) { pub fn clear_database_cache(&mut self) {
todo!() todo!()
......
...@@ -4,7 +4,7 @@ use crate::*; ...@@ -4,7 +4,7 @@ use crate::*;
/// Represent the possible types for a song. The custom field is here for /// Represent the possible types for a song. The custom field is here for
/// flexibility, we box it so it's not too big and because it won't be common. /// flexibility, we box it so it's not too big and because it won't be common.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum SongType { pub enum SongType {
OP, OP,
ED, ED,
...@@ -16,8 +16,7 @@ pub enum SongType { ...@@ -16,8 +16,7 @@ pub enum SongType {
/// Represent the possible origins for a song. The custom field is here for /// Represent the possible origins for a song. The custom field is here for
/// flexibility, we box it so it's not too big and because it won't be common. /// flexibility, we box it so it's not too big and because it won't be common.
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] #[derive(Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum SongOrigin { pub enum SongOrigin {
Anime, Anime,
VN, VN,
...@@ -28,7 +27,7 @@ pub enum SongOrigin { ...@@ -28,7 +27,7 @@ pub enum SongOrigin {
} }
/// Represent a global id for a kara, the pair (database, id). /// Represent a global id for a kara, the pair (database, id).
#[derive(Debug, Deserialize, Serialize, Getters, CopyGetters)] #[derive(Debug, Getters, CopyGetters)]
pub struct KaraId { pub struct KaraId {
#[getset(get = "pub")] #[getset(get = "pub")]
repo: SmallString, repo: SmallString,
...@@ -108,7 +107,7 @@ impl<'a> TaggedObject<'a> for KaraInfo { ...@@ -108,7 +107,7 @@ impl<'a> TaggedObject<'a> for KaraInfo {
} }
/// Represent what we want to override in a kara. /// Represent what we want to override in a kara.
#[derive(Debug, Clone, Deserialize, Serialize)] #[derive(Debug, Clone)]
pub enum KaraInfoOverride { pub enum KaraInfoOverride {
SongTitle(SmallString), SongTitle(SmallString),
SongSource(SmallString), SongSource(SmallString),
...@@ -153,3 +152,29 @@ impl KaraInfo { ...@@ -153,3 +152,29 @@ impl KaraInfo {
!= 0 != 0
} }
} }
impl From<&str> for SongOrigin {
fn from(value: &str) -> Self {
match value {
"anime" => SongOrigin::Anime,
"music" => SongOrigin::Music,
"autre" => SongOrigin::Autre,
"game" => SongOrigin::Game,
"vb" => SongOrigin::VN,
custom => SongOrigin::Custom(Box::new(custom.into())),
}
}
}
impl From<&str> for SongType {
fn from(value: &str) -> Self {
match value {
"OP" => SongType::OP,
"ED" => SongType::ED,
"IS" => SongType::IS,
"MV" => SongType::MV,
"OT" => SongType::OT,
custom => SongType::Custom(Box::new(custom.into())),
}
}
}
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