diff options
| author | Maiddog <[email protected]> | 2018-07-31 06:41:23 -0500 |
|---|---|---|
| committer | Alex M. M <[email protected]> | 2018-07-31 13:41:23 +0200 |
| commit | 21eb42f96f9721d4e004dbc70aedf60e6d1ae7c4 (patch) | |
| tree | c1cce5647092120b59cb441ee82bb27cd1d4e546 /src | |
| parent | Spaces between badges in readme (diff) | |
| download | serenity-21eb42f96f9721d4e004dbc70aedf60e6d1ae7c4.tar.xz serenity-21eb42f96f9721d4e004dbc70aedf60e6d1ae7c4.zip | |
Make GuildId::member use the cache when possible (#356)
Diffstat (limited to 'src')
| -rw-r--r-- | src/model/guild/guild_id.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index 9c3120a..ebe930e 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -444,7 +444,10 @@ impl GuildId { #[inline] pub fn leave(&self) -> Result<()> { http::leave_guild(self.0) } - /// Gets a user's [`Member`] for the guild by Id. + /// Gets a user's [`Member`] for the guild by Id. + /// + /// If the cache feature is enabled the cache will be checked + /// first. If not found it will resort to an http request. /// /// [`Guild`]: struct.Guild.html /// [`Member`]: struct.Member.html @@ -454,6 +457,13 @@ impl GuildId { } fn _member(&self, user_id: UserId) -> Result<Member> { + #[cfg(feature = "cache")] + { + if let Some(member) = CACHE.read().member(self.0, user_id) { + return Ok(member); + } + } + http::get_member(self.0, user_id.0) } |