Skip to content

Commit ad6c7f8

Browse files
committed
fix: return links in the order they are requested
using a set to remove duplicates from the set of symbols ended up randomizing their order.
1 parent 22bd71f commit ad6c7f8

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

bot/exts/info/doc/_cog.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,26 +268,22 @@ async def get_symbol_markdown(self, doc_item: DocItem) -> str:
268268
return "Unable to parse the requested symbol."
269269
return markdown
270270

271-
async def _get_symbols_items(self, symbols: list[str]) -> list[tuple[str, DocItem | None]]:
272-
"""
273-
Get DocItems for the given list of symbols, and update the stats for the fetched doc items.
274-
275-
Returns (symbol, None) for any symbol for which a DocItem could not be found.
276-
"""
271+
async def _get_symbols_items(self, symbols: list[str]) -> dict[str, DocItem | None]:
272+
"""Get DocItems for the given list of symbols, and update the stats for the fetched doc items."""
277273
if not self.refresh_event.is_set():
278274
log.debug("Waiting for inventories to be refreshed before processing item.")
279275
await self.refresh_event.wait()
280276

281277
# Ensure a refresh can't run in case of a context switch until the with block is exited
282278
with self.symbol_get_event:
283-
items: list[tuple[str, DocItem | None]] = []
284-
for symbol_name in set(symbols):
279+
items: dict[str, DocItem | None] = {}
280+
for symbol_name in symbols:
285281
symbol_name, doc_item = self.get_symbol_item(symbol_name)
286282
if doc_item:
287-
items.append((symbol_name, doc_item))
283+
items[symbol_name] = doc_item
288284
self.bot.stats.incr(f"doc_fetches.{doc_item.package}")
289285
else:
290-
items.append((symbol_name, None))
286+
items[symbol_name] = None
291287

292288
return items
293289

@@ -301,7 +297,7 @@ async def create_symbol_embed(self, symbol_name: str) -> discord.Embed | None:
301297
"""
302298
log.trace(f"Building embed for symbol `{symbol_name}`")
303299
_items = await self._get_symbols_items([symbol_name])
304-
symbol_name, doc_item = _items[0]
300+
doc_item = _items[symbol_name]
305301

306302
if doc_item is None:
307303
log.debug(f"{symbol_name=} does not exist.")
@@ -332,7 +328,7 @@ async def create_compact_doc_message(self, symbols: list[str]) -> str:
332328
items = await self._get_symbols_items(symbols)
333329
content = ""
334330
link_count = 0
335-
for symbol_name, doc_item in items:
331+
for symbol_name, doc_item in items.items():
336332
if link_count >= 10:
337333
break
338334
if doc_item is None:

0 commit comments

Comments
 (0)