Skip to content

Conversation

jonodrew
Copy link
Contributor

@jonodrew jonodrew commented Aug 24, 2025

I'm not completely happy with this yet.

I've written some helper methods to grab all of the 'things' a member is attending and find them once, when the controller method is called. This replaces the map loop that generated two queries per event.

However, I think there's some clash here. The set of Event, Meeting, and Workshop ids will have some overlap and the tests will therefore be flakey. Advice welcome

This removes a call to '#attending?' for every workshop, instead creating a single method to generate the list.

Running locally with a small sample, it reduced loading time for the homepage by 70%

Signed-off-by: jonathan.kerr <[email protected]>
This now checks if the object passed to the Presenter is `nil` and responds accordingly. I've updated the logic in the dashboard_controller.rb to reflect the change

Signed-off-by: jonathan.kerr <[email protected]>
There feels like a lot of repetition here, but I can't figure out how to remove it right now

Signed-off-by: jonathan.kerr <[email protected]>
In order to use the MemberPresenter more flexibly, I want to remove the constant checking. The Presenter should be able to intialise with a `nil` object and then deal with the consequences of that. This approach will return `false` to any method not defined on the presenter or the presented object.

Signed-off-by: jonathan.kerr <[email protected]>
Current count: 16 failures.

Signed-off-by: jonathan.kerr <[email protected]>
Apply the method across the events area, in the same way we did for workshops

Signed-off-by: jonathan.kerr <[email protected]>
@jonodrew jonodrew force-pushed the identify-slow-requests branch from f65f4da to e5f338b Compare August 24, 2025 12:18
Currently we call `event_organiser` on every event when creating the dashboard. I've rewritten it to cache some of the things a user might be an organiser of.

Signed-off-by: jonathan.kerr <[email protected]>
We don't need to check if a user is admin every single time, so I've cached the check

Signed-off-by: jonathan.kerr <[email protected]>
We don't need to load each chapter separately - let's get them all in one!

Signed-off-by: jonathan.kerr <[email protected]>
@jonodrew
Copy link
Contributor Author

In total, this cuts loading the front page down to below 4s

Signed-off-by: jonathan.kerr <[email protected]>
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module AttendanceConcerns
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is one concern I think this should just be AttendanceConcern same for the file name so it matches the following:

  1. Rails autoloading expectations
  2. ActiveSupport::Concern conventions
  3. The rails generate concern behaviour

@davidmillen50
Copy link
Contributor

In total, this cuts loading the front page down to below 4s

I'm interested to know more about the savings you hope to make. I just loaded the production front page in 3.42s will your changes reduce that?

role.eql?('Coach') ? coach_pairing_details(note) : student_pairing_details(tutorial, note)
end


Copy link
Contributor

Choose a reason for hiding this comment

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

are these two spaces needed?

= link_to event.chapter.name, event.chapter.slug, class: 'text-light text-decoration-none'
- if @user
- if @user.attending?(event.__getobj__)
- if !attending_ids.blank?
Copy link
Contributor

Choose a reason for hiding this comment

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

attending_ids.present? might be better here

- if @events.any?
%h3.mb-4 Upcoming Events
= render partial: 'events', locals: { grouped_events: @events }
= render partial: 'events', locals: { grouped_events: @events, attending_ids: @attending_ids}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you need a space before the closing }

%h5 Groups
%ul.list-unstyled.ms-0#subscriptions
- @member.groups.each do |group|
- member_groups = @member.groups
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably just do @member.groups.each etc

- if @user
- if @user.attending?(event.__getobj__)
- if !attending_ids.blank?
- if attending_ids.include?(event.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

as you mentioned in the PR description, this seems problematic if there is a crossover of ids between different event types.

extend ActiveSupport::Concern

def attending_workshops
current_user.nil? ? Set.new : current_user.workshop_invitations.accepted.pluck(:id).to_set
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

3 participants