aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shirayuki Nekomata <[email protected]>2020-02-04 12:23:29 +0700
committerGravatar Shirayuki Nekomata <[email protected]>2020-02-04 12:23:29 +0700
commit7f0e6733de8e2b6c3d13834916d790673547e1fb (patch)
tree1f1b8fa74b87163111086564afd15aa3f17c7231
parentMerge branch 'master' into fuzzy-tag-search (diff)
Fixed _last_fetch not being updated after each api call.
- Changed type of `self._last_fetch` to `float` and give it the initial value of `0.0` instead of `None` - Assigned `time.time()` to `time_now` to avoid calling this function twice. - Added `self._last_fetch = time_now` after calling the api call.
-rw-r--r--bot/cogs/tags.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py
index 7effaf754..9e06b702c 100644
--- a/bot/cogs/tags.py
+++ b/bot/cogs/tags.py
@@ -27,14 +27,16 @@ class Tags(Cog):
self.tag_cooldowns = {}
self._cache = {}
- self._last_fetch = None
+ self._last_fetch: float = 0.0
async def _get_tags(self, is_forced: bool = False) -> None:
- """Getting all tags."""
- # Refresh only when there's a more than 5m gap from last call.
- if is_forced or not self._last_fetch or time.time() - self._last_fetch > 5 * 60:
+ """Get all tags."""
+ # refresh only when there's a more than 5m gap from last call.
+ time_now: float = time.time()
+ if is_forced or not self._last_fetch or time_now - self._last_fetch > 5 * 60:
tags = await self.bot.api_client.get('bot/tags')
self._cache = {tag['title'].lower(): tag for tag in tags}
+ self._last_fetch = time_now
@staticmethod
def _fuzzy_search(search: str, target: str) -> bool: