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

RUST: The cache will also be saved -> don't need to import all the overrides at each launch

parent 1b85a38b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -9,15 +9,17 @@ use lru::LruCache;
/// cache, if its the playlists that are updated, we clear only the playlist, if
/// it's the database, we clear everything.
#[allow(dead_code)]
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct AmaDB {
/// Cache requests to lektord and patched karas. The first element is the
/// lektord entry, the second one is the patched version.
/// TODO: Find a structure that does COW to not duplicate too much
/// information in the patched version...
#[serde(skip, default = "new_empty_kara_lru")]
karas: LruCache<i64, (KaraInfo, Option<KaraInfo>)>,
/// The playlists. We don't save them...
#[serde(skip, default = "new_empty_playlist_lru")]
playlists: LruCache<SmallString, Playlist>,
/// The list of overrides, indexed by the local id of the kara.
......@@ -53,9 +55,22 @@ fn new_empty_playlist_lru() -> LruCache<SmallString, Playlist> {
)
}
impl Default for AmaDB {
fn default() -> Self {
Self {
karas: new_empty_kara_lru(),
playlists: new_empty_playlist_lru(),
overrides: Default::default(),
local_ids: Default::default(),
}
}
}
impl AmaDB {
/// Create a new empty [AmaDB].
pub fn new() -> Self {}
pub fn new() -> Self {
Default::default()
}
/// Clear the database cache, and only the caches about karas.
pub fn clear_database_cache(&mut self) {
......
......@@ -4,7 +4,7 @@ use crate::*;
/// 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.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum SongType {
OP,
ED,
......@@ -16,7 +16,7 @@ pub enum SongType {
/// 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.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum SongOrigin {
Anime,
VN,
......@@ -27,7 +27,7 @@ pub enum SongOrigin {
}
/// Represent a global id for a kara, the pair (database, id).
#[derive(Debug, Getters, CopyGetters)]
#[derive(Debug, Getters, CopyGetters, Serialize, Deserialize)]
pub struct KaraId {
#[getset(get = "pub")]
repo: SmallString,
......@@ -38,7 +38,7 @@ pub struct KaraId {
/// A list of informations about a kara. This is the data from lektor. When
/// queried we patch it with the overrides given by the user.
#[derive(Debug, Getters)]
#[derive(Debug, Getters, Serialize, Deserialize)]
#[getset(get = "pub")]
pub struct KaraInfo {
song_title: SmallString,
......@@ -107,7 +107,7 @@ impl<'a> TaggedObject<'a> for KaraInfo {
}
/// Represent what we want to override in a kara.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum KaraInfoOverride {
SongTitle(SmallString),
SongSource(SmallString),
......
......@@ -2,7 +2,7 @@
use crate::*;
#[derive(Debug, Getters)]
#[derive(Debug, Getters, Serialize, Deserialize)]
#[getset(get = "pub")]
pub struct Playlist {
name: SmallString,
......
......@@ -164,7 +164,7 @@ impl<'a> TaggedObject<'a> for SimpleTagSystem {
}
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
/// Represents a patch action to do on a tagged object.
pub enum TagOverride<TK: AsRef<str> + Clone, TV: AsRef<str>> {
/// Remove all tags.
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter