mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-04-18 00:08:54 +00:00
Add cache clear command
This commit is contained in:
parent
5998b37bd8
commit
dc973c93dc
4 changed files with 45 additions and 1 deletions
|
@ -218,6 +218,13 @@ impl CachedBeatmap {
|
|||
.await
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
/// Delete all of the caches.
|
||||
pub async fn clear_all(conn: impl Executor<'_, Database = Database>) -> Result<()> {
|
||||
conn.execute("DELETE FROM osu_cached_beatmapsets; DELETE FROM osu_cached_beatmaps;")
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CachedBeatmap {
|
||||
|
@ -291,6 +298,13 @@ impl CachedBeatmapContent {
|
|||
.await
|
||||
.map_err(Error::from)
|
||||
}
|
||||
|
||||
/// Delete all of the caches.
|
||||
pub async fn clear_all(conn: impl Executor<'_, Database = Database>) -> Result<()> {
|
||||
conn.execute("DELETE FROM osu_cached_beatmap_contents;")
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CachedBeatmapContent {
|
||||
|
|
|
@ -23,6 +23,12 @@ impl BeatmapMetaCache {
|
|||
BeatmapMetaCache { client, pool }
|
||||
}
|
||||
|
||||
/// Clean the cache.
|
||||
pub async fn clear(&self) -> Result<()> {
|
||||
models::CachedBeatmap::clear_all(&self.pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn to_cached_beatmap(beatmap: &Beatmap, mode: Option<Mode>) -> models::CachedBeatmap {
|
||||
models::CachedBeatmap {
|
||||
|
|
|
@ -122,7 +122,8 @@ pub async fn setup(
|
|||
check,
|
||||
top,
|
||||
server_rank,
|
||||
update_leaderboard
|
||||
update_leaderboard,
|
||||
clean_cache
|
||||
)]
|
||||
#[default_command(std)]
|
||||
struct Osu;
|
||||
|
@ -702,6 +703,23 @@ pub async fn top(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[command("cleancache")]
|
||||
#[owners_only]
|
||||
#[description = "Clean the beatmap cache."]
|
||||
#[usage = "[--oppai to clear oppai cache as well]"]
|
||||
#[max_args(1)]
|
||||
pub async fn clean_cache(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
let data = ctx.data.read().await;
|
||||
let meta_cache = data.get::<BeatmapMetaCache>().unwrap();
|
||||
meta_cache.clear().await?;
|
||||
if args.remains() == Some("--oppai") {
|
||||
let oppai = data.get::<BeatmapCache>().unwrap();
|
||||
oppai.clear().await?;
|
||||
}
|
||||
msg.reply_ping(ctx, "Beatmap cache cleared!").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_user(ctx: &Context, msg: &Message, mut args: Args, mode: Mode) -> CommandResult {
|
||||
let data = ctx.data.read().await;
|
||||
let user = to_user_id_query(args.single::<UsernameArg>().ok(), &data, msg).await?;
|
||||
|
|
|
@ -316,6 +316,12 @@ impl BeatmapCache {
|
|||
BeatmapCache { client, pool }
|
||||
}
|
||||
|
||||
/// Clean the cache.
|
||||
pub async fn clear(&self) -> Result<()> {
|
||||
models::CachedBeatmapContent::clear_all(&self.pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_beatmap(content: impl AsRef<str>) -> Result<BeatmapContent> {
|
||||
let content = content.as_ref();
|
||||
let metadata = osuparse::parse_beatmap(content)
|
||||
|
|
Loading…
Add table
Reference in a new issue