diff options
| author | Maiddog <[email protected]> | 2018-07-31 06:41:23 -0500 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-08-01 12:53:45 -0700 |
| commit | a4e97abad3d10d4ba7a059cff52b56f66c8226a7 (patch) | |
| tree | 6f1cf115d1051a87c1188f1fd86c84403fb4dec6 /src/model | |
| parent | Dump state in all codepaths in shard (diff) | |
| download | serenity-a4e97abad3d10d4ba7a059cff52b56f66c8226a7.tar.xz serenity-a4e97abad3d10d4ba7a059cff52b56f66c8226a7.zip | |
Make GuildId::member use the cache when possible (#356)
Diffstat (limited to 'src/model')
| -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) } |