feat: add caching to everything, should make all member interacts faster
All checks were successful
/ check_lfs (push) Successful in 13s
On_Push / lint_fmt (push) Successful in 24s
On_Push / lint_clippy (push) Successful in 25s
On_Push / build (push) Successful in 1m59s
On_Push / deploy (push) Successful in 17s

This commit is contained in:
silver 2025-07-07 22:22:25 +01:00
parent 3abbb8d485
commit e901f3ed74
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
6 changed files with 40 additions and 4 deletions

View file

@ -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<GuildId>) {
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<Sqlite>, ctx: &Context, config: &Config) {
}
}
}
}
}

View file

@ -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<GuildId>) {
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);

View file

@ -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<GuildId>) {
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);

View file

@ -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<GuildId>) {
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);

View file

@ -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<GuildId>) {
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);

View file

@ -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<GuildId>) {
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!");
}