Skip to content

Commit

Permalink
Refactor member.py and youtube_search.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rtk-rnjn committed Apr 14, 2024
1 parent 3dae967 commit edf3a31
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion events/guild/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ async def cog_unload(self):
)
for guild_id, set_member_muted in self.muted.items()
]
await self._bulk_update(operations)

await self.bot.guild_configurations.write_bulk(operations)
async def _bulk_update(self, operations: list, *, ordered: bool = False, chunk_size: int = 1000):
for i in range(0, len(operations), chunk_size):
await self.bot.guild_configurations.bulk_write(operations[i : i + chunk_size], ordered=ordered)


async def setup(bot: Parrot) -> None:
Expand Down
3 changes: 2 additions & 1 deletion utilities/youtube_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def __init__(self, max_results: int | None = 5) -> None:
self._cache: dict[str, list[dict]] = {}

async def close(self) -> None:
await self.session.close()
if hasattr(self, "session"):
await self.session.close()

async def init(self) -> None:
self.session = aiohttp.ClientSession()
Expand Down

0 comments on commit edf3a31

Please sign in to comment.