mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-19 16:58:55 +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,
|
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(),
|
||||||
|
|
|
@ -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(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)?;
|
||||||
|
|
Loading…
Add table
Reference in a new issue