Skip to content

Commit

Permalink
Put update_user_entry back into the cache
Browse files Browse the repository at this point in the history
Not really related to the events by any means
  • Loading branch information
arqunis committed Aug 11, 2017
1 parent eee857a commit 32de2cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 0 additions & 13 deletions src/cache/cache_events_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ pub(crate) trait CacheEventsImpl {
fn update_with_user_update(&mut self, event: &UserUpdateEvent) -> CurrentUser;

fn update_with_voice_state_update(&mut self, event: &VoiceStateUpdateEvent);

fn update_user_entry(&mut self, user: &User);
}

impl CacheEventsImpl for super::Cache {
Expand Down Expand Up @@ -526,15 +524,4 @@ impl CacheEventsImpl for super::Cache {
return;
}
}

fn update_user_entry(&mut self, user: &User) {
match self.users.entry(user.id) {
Entry::Vacant(e) => {
e.insert(Arc::new(RwLock::new(user.clone())));
},
Entry::Occupied(mut e) => {
e.get_mut().write().unwrap().clone_from(user);
},
}
}
}
13 changes: 12 additions & 1 deletion src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
//! [`Role`]: ../model/struct.Role.html
//! [`CACHE`]: ../struct.CACHE.html
//! [`http`]: ../http/index.html
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use std::default::Default;
use std::sync::{Arc, RwLock};
Expand Down Expand Up @@ -592,6 +592,17 @@ impl Cache {
pub fn user<U: Into<UserId>>(&self, user_id: U) -> Option<Arc<RwLock<User>>> {
self.users.get(&user_id.into()).cloned()
}

fn update_user_entry(&mut self, user: &User) {
match self.users.entry(user.id) {
Entry::Vacant(e) => {
e.insert(Arc::new(RwLock::new(user.clone())));
},
Entry::Occupied(mut e) => {
e.get_mut().write().unwrap().clone_from(user);
},
}
}
}

impl Default for Cache {
Expand Down

0 comments on commit 32de2cb

Please sign in to comment.