diff options
| author | 2022-02-13 18:52:16 +0000 | |
|---|---|---|
| committer | 2022-02-13 18:52:16 +0000 | |
| commit | 44afbcf5739ce8cb2174e9262ac0bf9e426d0ffa (patch) | |
| tree | e1dc8bc57e03d114511eddf114d499bc6354c617 | |
| parent | Merge pull request #12 from python-discord/fix-thread-update-event (diff) | |
Only sync thread archive status on startup
Since we can update threads during bot runtime, there is no need to sync archive status every time, just do this on startup.
Diffstat (limited to '')
| -rw-r--r-- | metricity/bot.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/metricity/bot.py b/metricity/bot.py index ea5973e..4ff44bc 100644 --- a/metricity/bot.py +++ b/metricity/bot.py @@ -116,9 +116,7 @@ async def sync_channels(guild: Guild) -> None: log.info("Channel synchronisation process complete, synchronising threads") - active_thread_ids = [] for thread in guild.threads: - active_thread_ids.append(str(thread.id)) if thread.parent and thread.parent.category: if thread.parent.category.id in BotConfig.ignore_categories: continue @@ -133,12 +131,15 @@ async def sync_channels(guild: Guild) -> None: ).apply() else: await insert_thread(thread) + channel_sync_in_progress.set() - async with db.transaction(): - async for db_thread in Thread.query.gino.iterate(): - await db_thread.update(archived=db_thread.id not in active_thread_ids).apply() - channel_sync_in_progress.set() +async def sync_thread_archive_state(guild: Guild) -> None: + """Sync the archive state of all threads in the database with the state in guild.""" + active_thread_ids = [str(thread.id) for thread in guild.threads] + async with db.transaction() as tx: + async for db_thread in tx.connection.iterate(Thread.query): + await db_thread.update(archived=db_thread.id not in active_thread_ids).apply() def gen_chunks( |