Skip to content

Commit

Permalink
Merge pull request #9 from bravosierra99/master
Browse files Browse the repository at this point in the history
I'll cache you outside
  • Loading branch information
jnawk authored Dec 22, 2020
2 parents d7dc6cf + b848056 commit 46420cf
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions quart_discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,27 @@ async def fetch_connections() -> list:
return await models.UserConnection.fetch_from_api()

@staticmethod
async def fetch_guilds() -> list:
async def fetch_guilds(use_cache=True) -> list:
"""This method returns list of guild objects from internal cache if it exists otherwise makes an API
call to do so.
Parameters
----------
use_cache : bool, optional
can be set to False to avoid using the cache.
Returns
-------
list
List of :py:class:`quart_discord.models.Guild` objects.
"""
user = models.User.get_from_cache()
try:
if user.guilds is not None:
return user.guilds
except AttributeError:
pass
if use_cache:
user = models.User.get_from_cache()
try:
if user.guilds is not None:
return user.guilds
except AttributeError:
pass

return await models.Guild.fetch_from_api()

0 comments on commit 46420cf

Please sign in to comment.