Skip to content

Commit

Permalink
Use a generator isntead of a list to hold the members to sync
Browse files Browse the repository at this point in the history
This reduces the memory required on bot startup
  • Loading branch information
ChrisLovering committed Jun 6, 2024
1 parent e302fe2 commit 2284ec8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions metricity/exts/event_listeners/startup_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def sync_guild(self) -> None:
await sess.execute(update(models.User).values(in_guild=False))
await sess.commit()

users = [
users = (
{
"id": str(user.id),
"name": user.name,
Expand All @@ -54,12 +54,12 @@ async def sync_guild(self) -> None:
"pending": user.pending,
}
for user in guild.members
]
)

user_chunks = discord.utils.as_chunks(users, 500)
created = 0
updated = 0
total_users = len(users)
total_users = len(guild.members)

log.info("Performing bulk upsert of %d rows in %d chunks", total_users, math.ceil(total_users / 500))

Expand Down

0 comments on commit 2284ec8

Please sign in to comment.