mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 08:48:54 +00:00
osu: Fix caches
This commit is contained in:
parent
c18d8f48d0
commit
421cfd46af
3 changed files with 8 additions and 10 deletions
|
@ -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<Client>,
|
||||
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<Client>) -> Self {
|
||||
BeatmapMetaCache {
|
||||
client,
|
||||
cache: DashMap::new(),
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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<oppai_rs::Mode>,
|
||||
mods: impl Into<oppai_rs::Mods>,
|
||||
) -> Result<f32, CommandError> {
|
||||
) -> Result<f32> {
|
||||
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<oppai_rs::Mode>,
|
||||
mods: impl Into<oppai_rs::Mods>,
|
||||
) -> Result<BeatmapInfo, CommandError> {
|
||||
) -> Result<BeatmapInfo> {
|
||||
let mut oppai = oppai_rs::Oppai::new_from_content(&self.content[..])?;
|
||||
if let Some(mode) = mode {
|
||||
oppai.mode(mode)?;
|
||||
|
|
Loading…
Add table
Reference in a new issue