From 421cfd46afce85998c87017b52cd8d6ba5343d1f Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Mon, 7 Sep 2020 19:01:08 -0400 Subject: [PATCH] osu: Fix caches --- youmubot-osu/src/discord/beatmap_cache.rs | 6 +++--- youmubot-osu/src/discord/cache.rs | 7 +++---- youmubot-osu/src/discord/oppai_cache.rs | 5 ++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/youmubot-osu/src/discord/beatmap_cache.rs b/youmubot-osu/src/discord/beatmap_cache.rs index f01e04e..2528dd1 100644 --- a/youmubot-osu/src/discord/beatmap_cache.rs +++ b/youmubot-osu/src/discord/beatmap_cache.rs @@ -3,13 +3,13 @@ use crate::{ Client, }; use dashmap::DashMap; +use std::sync::Arc; use youmubot_prelude::*; /// BeatmapMetaCache intercepts beatmap-by-id requests and caches them for later recalling. /// Does not cache non-Ranked beatmaps. -#[derive(Debug)] pub struct BeatmapMetaCache { - client: Client, + client: Arc, cache: DashMap<(u64, Mode), Beatmap>, } @@ -19,7 +19,7 @@ impl TypeMapKey for BeatmapMetaCache { impl BeatmapMetaCache { /// Create a new beatmap cache. - pub fn new(client: Client) -> Self { + pub fn new(client: Arc) -> Self { BeatmapMetaCache { client, cache: DashMap::new(), diff --git a/youmubot-osu/src/discord/cache.rs b/youmubot-osu/src/discord/cache.rs index b700205..37bcab4 100644 --- a/youmubot-osu/src/discord/cache.rs +++ b/youmubot-osu/src/discord/cache.rs @@ -9,10 +9,9 @@ pub(crate) fn save_beatmap( channel_id: ChannelId, bm: &BeatmapWithMode, ) -> Result<()> { - let db = OsuLastBeatmap::open(data); - let mut db = db.borrow_mut()?; - - db.insert(channel_id, (bm.0.clone(), bm.mode())); + OsuLastBeatmap::open(data) + .borrow_mut()? + .insert(channel_id, (bm.0.clone(), bm.mode())); Ok(()) } diff --git a/youmubot-osu/src/discord/oppai_cache.rs b/youmubot-osu/src/discord/oppai_cache.rs index fbb6228..b5fa4ab 100644 --- a/youmubot-osu/src/discord/oppai_cache.rs +++ b/youmubot-osu/src/discord/oppai_cache.rs @@ -1,4 +1,3 @@ -use serenity::framework::standard::CommandError; use std::ffi::CString; use youmubot_prelude::*; @@ -24,7 +23,7 @@ impl BeatmapContent { accuracy: f32, mode: Option, mods: impl Into, - ) -> Result { + ) -> Result { let mut oppai = oppai_rs::Oppai::new_from_content(&self.content[..])?; oppai.combo(combo)?.accuracy(accuracy)?.mods(mods.into()); if let Some(mode) = mode { @@ -38,7 +37,7 @@ impl BeatmapContent { &self, mode: Option, mods: impl Into, - ) -> Result { + ) -> Result { let mut oppai = oppai_rs::Oppai::new_from_content(&self.content[..])?; if let Some(mode) = mode { oppai.mode(mode)?;