diff options
| author | 2021-01-10 00:11:16 +0100 | |
|---|---|---|
| committer | 2021-01-10 06:16:10 +0100 | |
| commit | 50bb3439824277991124b888d0b46c5936c2efce (patch) | |
| tree | fbf480a6e009c662eff22f729b3cab46568d2417 | |
| parent | Stop scheduled and long running tasks on cog unload (diff) | |
Handle equal DocItems in the queue
This could be handled by using sets to hold the items in _page_symbols,
but ultimately the check has a much smaller cost than having
thousands of sets for the urls.
Because we create futures for every item that ends up in the queue we
can also skip the .get is None check and instead fetch the
future directly from the dict
| -rw-r--r-- | bot/exts/info/doc/_cog.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py index 61ac35b6f..cee482c30 100644 --- a/bot/exts/info/doc/_cog.py +++ b/bot/exts/info/doc/_cog.py @@ -157,6 +157,11 @@ class CachedParser: while self._queue: item, soup = self._queue.pop() try: + if (future := self._item_futures[item]).done(): + # Some items are present in the inventories multiple times under different symbols, + # if we already parsed an equal item, we can just skip it. + continue + markdown = await bot_instance.loop.run_in_executor( None, partial(get_symbol_markdown, soup, item), @@ -166,8 +171,7 @@ class CachedParser: except Exception: log.exception(f"Unexpected error when handling {item}") else: - if (future := self._item_futures.get(item)) is not None: - future.set_result(markdown) + future.set_result(markdown) await asyncio.sleep(0.1) finally: self._parse_task = None |