Skip to content

Commit

Permalink
fix: correct cache updating
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Oct 26, 2024
1 parent 06508cc commit 44a280e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 10 additions & 7 deletions gateway/src/handle_events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;
use std::sync::atomic::Ordering;
use tokio::sync::{mpsc, Mutex, RwLock};
use tokio::sync::{Mutex};
use twilight_cache_inmemory::InMemoryCache;
use twilight_gateway::Shard;
use twilight_http::Client;
Expand Down Expand Up @@ -43,19 +43,22 @@ pub async fn handle_events(http_client: Arc<Client>, app_id: Id<ApplicationMarke
}
};

{
let cache = cache.lock().await;
cache.update(&event);
}
let mut cache = cache.lock().await;

match &event {
Event::GatewayClose(close_event) => {
},
Event::InteractionCreate(interaction) => {
cache.update(&event);
let framework_clone = Arc::clone(&framework);
framework_clone.process(interaction.0.clone()).await;
},

Event::MessageDelete(message) => {
message_delete::handle_message_delete_events(message, &mut cache).await;
cache.update(&event);
}

_ => {
cache.update(&event);
tracing::info!(kind = ?event.kind(), shard = ?shard.id(), "received event of type {:?}", event.kind());
}
}
Expand Down
6 changes: 2 additions & 4 deletions gateway/src/handlers/message_delete.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use std::sync::Arc;
use tokio::sync::{Mutex};
use tracing::{info, warn};
use twilight_cache_inmemory::InMemoryCache;
use twilight_model::gateway::payload::incoming::MessageDelete;

pub(crate) async fn handle_message_delete_events(event: &MessageDelete, cache: Arc<Mutex<InMemoryCache>>) {
let cache_lock = cache.lock().await;
let message = cache_lock.message(event.id);
pub(crate) async fn handle_message_delete_events(event: &MessageDelete, cache: &mut InMemoryCache) {
let message = cache.message(event.id);

match message {
Some(msg) => {
Expand Down

0 comments on commit 44a280e

Please sign in to comment.