osu: Fix caches

This commit is contained in:
Natsu Kagami 2020-09-07 19:01:08 -04:00
parent c18d8f48d0
commit 421cfd46af
Signed by: nki
GPG key ID: 73376E117CD20735
3 changed files with 8 additions and 10 deletions

View file

@ -3,13 +3,13 @@ use crate::{
Client, Client,
}; };
use dashmap::DashMap; use dashmap::DashMap;
use std::sync::Arc;
use youmubot_prelude::*; use youmubot_prelude::*;
/// BeatmapMetaCache intercepts beatmap-by-id requests and caches them for later recalling. /// BeatmapMetaCache intercepts beatmap-by-id requests and caches them for later recalling.
/// Does not cache non-Ranked beatmaps. /// Does not cache non-Ranked beatmaps.
#[derive(Debug)]
pub struct BeatmapMetaCache { pub struct BeatmapMetaCache {
client: Client, client: Arc<Client>,
cache: DashMap<(u64, Mode), Beatmap>, cache: DashMap<(u64, Mode), Beatmap>,
} }
@ -19,7 +19,7 @@ impl TypeMapKey for BeatmapMetaCache {
impl BeatmapMetaCache { impl BeatmapMetaCache {
/// Create a new beatmap cache. /// Create a new beatmap cache.
pub fn new(client: Client) -> Self { pub fn new(client: Arc<Client>) -> Self {
BeatmapMetaCache { BeatmapMetaCache {
client, client,
cache: DashMap::new(), cache: DashMap::new(),

View file

@ -9,10 +9,9 @@ pub(crate) fn save_beatmap(
channel_id: ChannelId, channel_id: ChannelId,
bm: &BeatmapWithMode, bm: &BeatmapWithMode,
) -> Result<()> { ) -> Result<()> {
let db = OsuLastBeatmap::open(data); OsuLastBeatmap::open(data)
let mut db = db.borrow_mut()?; .borrow_mut()?
.insert(channel_id, (bm.0.clone(), bm.mode()));
db.insert(channel_id, (bm.0.clone(), bm.mode()));
Ok(()) Ok(())
} }

View file

@ -1,4 +1,3 @@
use serenity::framework::standard::CommandError;
use std::ffi::CString; use std::ffi::CString;
use youmubot_prelude::*; use youmubot_prelude::*;
@ -24,7 +23,7 @@ impl BeatmapContent {
accuracy: f32, accuracy: f32,
mode: Option<oppai_rs::Mode>, mode: Option<oppai_rs::Mode>,
mods: impl Into<oppai_rs::Mods>, mods: impl Into<oppai_rs::Mods>,
) -> Result<f32, CommandError> { ) -> Result<f32> {
let mut oppai = oppai_rs::Oppai::new_from_content(&self.content[..])?; let mut oppai = oppai_rs::Oppai::new_from_content(&self.content[..])?;
oppai.combo(combo)?.accuracy(accuracy)?.mods(mods.into()); oppai.combo(combo)?.accuracy(accuracy)?.mods(mods.into());
if let Some(mode) = mode { if let Some(mode) = mode {
@ -38,7 +37,7 @@ impl BeatmapContent {
&self, &self,
mode: Option<oppai_rs::Mode>, mode: Option<oppai_rs::Mode>,
mods: impl Into<oppai_rs::Mods>, mods: impl Into<oppai_rs::Mods>,
) -> Result<BeatmapInfo, CommandError> { ) -> Result<BeatmapInfo> {
let mut oppai = oppai_rs::Oppai::new_from_content(&self.content[..])?; let mut oppai = oppai_rs::Oppai::new_from_content(&self.content[..])?;
if let Some(mode) = mode { if let Some(mode) = mode {
oppai.mode(mode)?; oppai.mode(mode)?;