Skip to content

Conversation

@Droid00000
Copy link
Collaborator

@Droid00000 Droid00000 commented Dec 7, 2025

Summary

Currently, role-caching has a problem. Creating a role with the bot causes a race condition to occur where the created role is cached twice. The code already tries to prevent this by checking if the role already exists, but to no avail. I can reproduce this race every time I create a role with the bot, so I don't think this is just some one-off case that we should ignore.

Currently, my solution is to internally store the roles in a hash keyed by ID (this was actually already being done @roles_by_id by the IVAR would never be updated after initial data saturation), and then serialize the map back into an array when the user calls #roles. One additional benefit of storing the roles in a hash is that lookups by ID are a lot faster now. This should not have any user-facing changes except that there isn't a race condition anymore.

This also seemed like a good chance to simplify how we update role data. In the spirit of #400, I believe that it's in our best interests to stop maintaining 3 different methods to update data and DRY things up to use a central function. This led me to realizing that I misspelled colour and used the American spelling accidentally. This should not have any user-facing changes because these are not publicly documented methods and are explicitly marked as FOR INTERNAL USE ONLY.

Fixed

Closes #177.

@Droid00000 Droid00000 force-pushed the feat/rework-role-caching branch from 7050a20 to cfe276a Compare December 25, 2025 05:18
@Droid00000 Droid00000 force-pushed the feat/rework-role-caching branch from 3a762f5 to e2cae00 Compare December 25, 2025 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create_role caches role twice

1 participant