Skip to content

Commit db22e38

Browse files
committed
Add debug performance logs for in_guild sync
1 parent f69fb12 commit db22e38

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

metricity/exts/event_listeners/startup_sync.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""An ext to sync the guild when the bot starts up."""
22

33
import math
4+
import time
45

56
import discord
67
from discord.ext import commands
@@ -25,7 +26,7 @@ def __init__(self, bot: Bot) -> None:
2526
self.bot = bot
2627
scheduling.create_task(self.sync_guild())
2728

28-
async def sync_guild(self) -> None:
29+
async def sync_guild(self) -> None: # noqa: PLR0914
2930
"""Sync all channels and members in the guild."""
3031
await self.bot.wait_until_guild_available()
3132

@@ -96,16 +97,30 @@ async def sync_guild(self) -> None:
9697
users_updated = 0
9798
guild_member_ids = {str(member.id) for member in guild.members}
9899
async with async_session() as sess:
100+
start = time.perf_counter()
99101

100102
stmt = select(models.User).filter_by(in_guild=True).options(load_only(models.User.id))
101103
res = await sess.execute(stmt)
102104
in_guild_users = res.scalars()
105+
query = time.perf_counter()
106+
103107
for user in in_guild_users:
104108
if user.id not in guild_member_ids:
105109
users_updated += 1
106110
user.in_guild = False
111+
proc = time.perf_counter()
112+
107113
await sess.commit()
108-
log.info("User in_guild sync updated %d users to be off guild", users_updated)
114+
end = time.perf_counter()
115+
116+
log.debug(
117+
"in_guild sync: total time %fs, query %fs, processing %fs, commit %fs",
118+
end - start,
119+
query - start,
120+
proc - query,
121+
end - proc,
122+
)
123+
log.info("User in_guild sync updated %d users to be off guild", users_updated)
109124
log.info("User sync complete")
110125

111126
self.bot.sync_process_complete.set()

0 commit comments

Comments
 (0)