From e901f3ed74120cb533b6eff7a873a8cd07776efd Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 7 Jul 2025 22:22:25 +0100 Subject: [PATCH] feat: add caching to everything, should make all member interacts faster --- src/bin/cleanup_committee.rs | 6 +++--- src/bin/update_committee.rs | 9 +++++++++ src/bin/update_data.rs | 9 +++++++++ src/bin/update_server-icon.rs | 9 +++++++++ src/bin/update_users.rs | 9 +++++++++ src/main.rs | 2 +- 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/bin/cleanup_committee.rs b/src/bin/cleanup_committee.rs index 7d2ea5a..a2c3772 100644 --- a/src/bin/cleanup_committee.rs +++ b/src/bin/cleanup_committee.rs @@ -7,7 +7,7 @@ use serenity::{ }; use skynet_discord_bot::common::database::{db_init, DataBase}; -use skynet_discord_bot::common::set_roles::committee::{db_roles_get}; +use skynet_discord_bot::common::set_roles::committee::db_roles_get; use skynet_discord_bot::{get_config, Config}; use sqlx::{Pool, Sqlite}; use std::{process, sync::Arc}; @@ -51,7 +51,7 @@ struct Handler; impl EventHandler for Handler { async fn cache_ready(&self, ctx: Context, guilds: Vec) { for guild in guilds { - ctx.shard.chunk_guild(guild, Some(500), false, ChunkGuildFilter::None, None); + ctx.shard.chunk_guild(guild, Some(2000), false, ChunkGuildFilter::None, None); } println!("Cache built successfully!"); } @@ -126,4 +126,4 @@ async fn cleanup(db: &Pool, ctx: &Context, config: &Config) { } } } -} \ No newline at end of file +} diff --git a/src/bin/update_committee.rs b/src/bin/update_committee.rs index d2026c0..2eef977 100644 --- a/src/bin/update_committee.rs +++ b/src/bin/update_committee.rs @@ -1,3 +1,4 @@ +use serenity::all::{ChunkGuildFilter, GuildId}; use serenity::{ async_trait, client::{Context, EventHandler}, @@ -23,6 +24,7 @@ async fn main() { // Build our client. let mut client = Client::builder(&config.discord_token, intents) .event_handler(Handler {}) + .cache_settings(serenity::cache::Settings::default()) .await .expect("Error creating client"); @@ -41,6 +43,13 @@ async fn main() { struct Handler; #[async_trait] impl EventHandler for Handler { + async fn cache_ready(&self, ctx: Context, guilds: Vec) { + for guild in guilds { + ctx.shard.chunk_guild(guild, Some(2000), false, ChunkGuildFilter::None, None); + } + println!("Cache built successfully!"); + } + async fn ready(&self, ctx: Context, ready: Ready) { let ctx = Arc::new(ctx); println!("{} is connected!", ready.user.name); diff --git a/src/bin/update_data.rs b/src/bin/update_data.rs index 2d36892..d184ccd 100644 --- a/src/bin/update_data.rs +++ b/src/bin/update_data.rs @@ -1,3 +1,4 @@ +use serenity::all::{ChunkGuildFilter, GuildId}; use serenity::{ async_trait, client::{Context, EventHandler}, @@ -27,6 +28,7 @@ async fn main() { // Build our client. let mut client = Client::builder(&config.discord_token, intents) .event_handler(Handler {}) + .cache_settings(serenity::cache::Settings::default()) .await .expect("Error creating client"); @@ -45,6 +47,13 @@ async fn main() { struct Handler; #[async_trait] impl EventHandler for Handler { + async fn cache_ready(&self, ctx: Context, guilds: Vec) { + for guild in guilds { + ctx.shard.chunk_guild(guild, Some(2000), false, ChunkGuildFilter::None, None); + } + println!("Cache built successfully!"); + } + async fn ready(&self, ctx: Context, ready: Ready) { let ctx = Arc::new(ctx); println!("{} is connected!", ready.user.name); diff --git a/src/bin/update_server-icon.rs b/src/bin/update_server-icon.rs index ff4cef9..2c093f9 100644 --- a/src/bin/update_server-icon.rs +++ b/src/bin/update_server-icon.rs @@ -1,3 +1,4 @@ +use serenity::all::{ChunkGuildFilter, GuildId}; use serenity::{ async_trait, client::{Context, EventHandler}, @@ -25,6 +26,7 @@ async fn main() { // Build our client. let mut client = Client::builder(&config.discord_token, intents) .event_handler(Handler {}) + .cache_settings(serenity::cache::Settings::default()) .await .expect("Error creating client"); @@ -43,6 +45,13 @@ async fn main() { struct Handler; #[async_trait] impl EventHandler for Handler { + async fn cache_ready(&self, ctx: Context, guilds: Vec) { + for guild in guilds { + ctx.shard.chunk_guild(guild, Some(2000), false, ChunkGuildFilter::None, None); + } + println!("Cache built successfully!"); + } + async fn ready(&self, ctx: Context, ready: Ready) { let ctx = Arc::new(ctx); println!("{} is connected!", ready.user.name); diff --git a/src/bin/update_users.rs b/src/bin/update_users.rs index 3617d14..27dc1d6 100644 --- a/src/bin/update_users.rs +++ b/src/bin/update_users.rs @@ -1,3 +1,4 @@ +use serenity::all::{ChunkGuildFilter, GuildId}; use serenity::{ async_trait, client::{Context, EventHandler}, @@ -23,6 +24,7 @@ async fn main() { // Build our client. let mut client = Client::builder(&config.discord_token, intents) .event_handler(Handler {}) + .cache_settings(serenity::cache::Settings::default()) .await .expect("Error creating client"); @@ -41,6 +43,13 @@ async fn main() { struct Handler; #[async_trait] impl EventHandler for Handler { + async fn cache_ready(&self, ctx: Context, guilds: Vec) { + for guild in guilds { + ctx.shard.chunk_guild(guild, Some(2000), false, ChunkGuildFilter::None, None); + } + println!("Cache built successfully!"); + } + async fn ready(&self, ctx: Context, ready: Ready) { let ctx = Arc::new(ctx); println!("{} is connected!", ready.user.name); diff --git a/src/main.rs b/src/main.rs index 2770db7..b09fb7a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ impl EventHandler for Handler { // this caches members of all servers teh bot is in async fn cache_ready(&self, ctx: Context, guilds: Vec) { for guild in guilds { - ctx.shard.chunk_guild(guild, Some(500), false, ChunkGuildFilter::None, None); + ctx.shard.chunk_guild(guild, Some(2000), false, ChunkGuildFilter::None, None); } println!("Cache built successfully!"); }