Skip to content

Conversation

@gnclmorais
Copy link
Contributor

Fixes #2411 by creating a new Member scope and loading only “manager” members, i.e. admins or organisers or a chapter.

Only admins or organisers can create new events, so we were loading
thousands of students… Not anymore.

Fixes codebar#2411

scope :with_skill, ->(skill_name) { tagged_with(skill_name) }

scope :admin, -> { with_role(:admin) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gnclmorais my Rails is so rusty, could you explain why we needed to define the :admin, and :organiser scopes here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One reason for having scopes named like this is that it enables the creation of a very legible manager scope: scope :manager, -> { admin.or(organiser).distinct } reads quite clearly.

The manager? method seems to have a fast-path is_admin? first, before querying the more-expensive has_role? call.

Looks nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason was pointed out by Olle: by defining the scopes, we create building blocks that can be reused anywhere and, most importantly for this PR, allows us to express in a clear way that a manager is either an admin or an organiser.

The manager? method came from moving the code that was on app/controllers/application_controller.rb to a more suitable place (i.e. it should be the Member model to own the s_admin? || has_role?(:organiser, :any) code).

Copy link
Contributor

@matyikriszta matyikriszta Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gnclmorais I think I asked my question wrong. I wanted to know where the :admin and organiser scopes were being called but I went back and re-read the :manager scope definition and answered my own question, I didn't read it closely enough and couldn't see where they were called. Thanks for the update.

Copy link
Collaborator

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use this!

@gnclmorais gnclmorais merged commit 6e56c17 into codebar:master Dec 8, 2025
2 checks passed
@gnclmorais gnclmorais deleted the reduce-members-loaded-on-new-event branch December 8, 2025 14:07
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.

"New event" admin page is slow to load and frequently times out.

3 participants