aboutsummaryrefslogtreecommitdiff
path: root/src/model/user.rs
diff options
context:
space:
mode:
authorMaiddog <[email protected]>2017-08-22 15:03:42 -0500
committeralex <[email protected]>2017-08-22 22:03:42 +0200
commitbfdb57cdf35721f4953d436a819745ac5d44295e (patch)
treef1b7751c36e2fd6f54a805d8c0574f06fb2b9a19 /src/model/user.rs
parentMake args empty when no arguments are passed. (#143) (diff)
downloadserenity-bfdb57cdf35721f4953d436a819745ac5d44295e.tar.xz
serenity-bfdb57cdf35721f4953d436a819745ac5d44295e.zip
Use cache when possible in UserId's get method (#146)
Diffstat (limited to 'src/model/user.rs')
-rw-r--r--src/model/user.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/model/user.rs b/src/model/user.rs
index d3cb72d..c32eeb8 100644
--- a/src/model/user.rs
+++ b/src/model/user.rs
@@ -742,7 +742,16 @@ impl UserId {
///
/// **Note**: The current user must be a bot user.
#[inline]
- pub fn get(&self) -> Result<User> { http::get_user(self.0) }
+ pub fn get(&self) -> Result<User> {
+ #[cfg(feature = "cache")]
+ {
+ if let Some(user) = CACHE.read().unwrap().user(*self) {
+ return Ok(user.read().unwrap().clone());
+ }
+ }
+
+ http::get_user(self.0)
+ }
}
impl From<CurrentUser> for UserId {