aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2023-09-04 22:10:57 +0100
committerGravatar Joe Banks <[email protected]>2023-09-04 22:10:57 +0100
commit7a72fc8fd53aa70f8382c4610f919ab453c97c6e (patch)
tree34a9ea6249c90618a7171d1962a026ef898dbc90
parentshow remaining users in upsert job (diff)
refactoring of count storage
-rw-r--r--metricity/exts/event_listeners/guild_listeners.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/metricity/exts/event_listeners/guild_listeners.py b/metricity/exts/event_listeners/guild_listeners.py
index 4a36a91..10ec2c3 100644
--- a/metricity/exts/event_listeners/guild_listeners.py
+++ b/metricity/exts/event_listeners/guild_listeners.py
@@ -1,5 +1,7 @@
"""An ext to listen for guild (and guild channel) events and syncs them to the database."""
+import math
+
import discord
from discord.ext import commands
from pydis_core.utils import logging, scheduling
@@ -53,11 +55,12 @@ class GuildListeners(commands.Cog):
for user in guild.members
]
- log.info("Performing bulk upsert of %d rows", len(users))
-
user_chunks = discord.utils.as_chunks(users, 500)
created = 0
updated = 0
+ total_users = len(users)
+
+ log.info("Performing bulk upsert of %d rows in %d chunks", total_users, math.ceil(total_users / 500))
async with async_session() as sess:
for chunk in user_chunks:
@@ -86,7 +89,7 @@ class GuildListeners(commands.Cog):
updated += [obj[0] != 0 for obj in objs].count(True)
log.info("User upsert: inserted %d rows, updated %d rows, done %d rows, %d rows remaining",
- created, updated, created + updated, len(users) - (created + updated))
+ created, updated, created + updated, total_users - (created + updated))
await sess.commit()