Feature - Optimise purge functionality#47
Conversation
…associated channels
There was a problem hiding this comment.
Review looks good generally, but let's make a few safety modifications:
-
Create First, Delete Last: Let's move the new role creation to happen before we delete the old role. Currently, if creation fails, we've already deleted the old role and lost its configuration permanently. We should only delete the old role once the new one is successfully established.
-
Migrate Permissions Safely: Along with the "create first" change, let's copy all channel overwrites to the new role before deleting the old one. This ensures data integrity if the copy process errors out halfway through.
-
Remove Role Reordering: Please remove the restoreRolePositionBestEffort logic. It requires submitting the entire server role list to the API, which risks scrambling the hierarchy if the cache is stale. It is safer to let the new role spawn at the bottom.
-
Rate Limiting: In the reapplyRoleOverwrites loop, please add a small sleep (e.g., time.Sleep(200 * time.Millisecond)) between iterations. Without this, we risk hitting rate limits by dumping 50+ permission write requests to the Discord API instantly.
Because of this sleep, it would be a good idea to wrap the purge logic in a goroutine so we don't block the main bot thread/heartbeat. We can defer the ephemeral response and have the goroutine reply to it when completed. Not strictly necessary, though.
No description provided.