-
Notifications
You must be signed in to change notification settings - Fork 25
Enhance /deaths, /levels and /timeline timeout by caching call to get member #135
Conversation
PR modified to also add caching to |
cogs/tibia.py
Outdated
@@ -221,6 +225,15 @@ def __init__(self, bot: NabBot): | |||
except CannotPaginate as e: | |||
await ctx.send(e) | |||
|
|||
@staticmethod | |||
def _get_cached_user_(self, user_id, user_unknown, users_cache, user_servers): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a cog, all commands are listed first in alphabetical order, followed by auxiliary functions, this should be moved accordingly.
cogs/tibia.py
Outdated
member_user = self.bot.get_member(user_id, user_servers) | ||
cached_user = user_unknown if member_user is None else member_user | ||
users_cache[user_id] = cached_user | ||
return cached_user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to have this return Union[User, None]
instead of Union[str, User]
so the possible values are similar, and in the implementations you don't have to deal with having a variable for "user_unknown" to compare on later.
Instead of using Dict.get()
, you can use key in Dict
to check if the user is in the cache, if it's not, then fetch.
I know I have committed this sin in the past, but I'm working on it!
Just wanted to add that, other than those minor details, this is a very good solution. |
Perfect, thanks! |
Bot searches all entries to get first 100/200 visible entries for the user that executed the command.
Every entry would then execute a call into
get_member
, and this would take some time, which in turn could make the bot timeout while waiting.By introducing the cache, the same members will not be searched repeatedly and the performance is increased a lot.