aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-05-02 22:01:37 -0700
committerZeyla Hellyer <[email protected]>2017-05-02 22:01:37 -0700
commit9a69b76bc0870f609a9dddca1e2583c524c4cf37 (patch)
treee853cc96112f15629c3cfb321cf2cb5926d28d90 /src
parentUse constant for preset permissions (diff)
downloadserenity-9a69b76bc0870f609a9dddca1e2583c524c4cf37.tar.xz
serenity-9a69b76bc0870f609a9dddca1e2583c524c4cf37.zip
Return preset from Member::find_guild if possible
If a value is present for `Member::guild_id` when calling `Member::find_guild`, return that value instead of searching the cache. This can potentially save a large amount of calculations and time.
Diffstat (limited to 'src')
-rw-r--r--src/model/guild/member.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs
index 630610f..5da7d7c 100644
--- a/src/model/guild/member.rs
+++ b/src/model/guild/member.rs
@@ -163,15 +163,24 @@ impl Member {
/// Finds the Id of the [`Guild`] that the member is in.
///
+ /// Returns the value of [`Member::guild_id`] if present. Otherwise searches
+ /// the [`Cache`] for the Id.
+ ///
/// # Errors
///
/// Returns a [`ClientError::GuildNotFound`] if the guild could not be
/// found.
///
+ /// [`Cache`]: ../ext/cache/struct.Cache.html
/// [`ClientError::GuildNotFound`]: ../client/enum.ClientError.html#variant.GuildNotFound
/// [`Guild`]: struct.Guild.html
+ /// [`Member::guild_id`]: struct.Member.html#structfield.guild_id
#[cfg(feature="cache")]
pub fn find_guild(&self) -> Result<GuildId> {
+ if let Some(guild_id) = self.guild_id {
+ return Ok(guild_id);
+ }
+
for guild in CACHE.read().unwrap().guilds.values() {
let guild = guild.read().unwrap();