Conversation
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 <3410350+jonodrew@users.noreply.github.com>
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 <3410350+jonodrew@users.noreply.github.com>
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 <3410350+jonodrew@users.noreply.github.com>
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 <3410350+jonodrew@users.noreply.github.com>
Current count: 16 failures. Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
This reverts commit f909f8b.
Apply the method across the events area, in the same way we did for workshops Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
f65f4da to
e5f338b
Compare
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 <3410350+jonodrew@users.noreply.github.com>
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 <3410350+jonodrew@users.noreply.github.com>
We don't need to load each chapter separately - let's get them all in one! Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
|
In total, this cuts loading the front page down to below 4s |
Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
Signed-off-by: jonathan.kerr <3410350+jonodrew@users.noreply.github.com>
| @@ -0,0 +1,13 @@ | |||
| # frozen_string_literal: true | |||
|
|
|||
| module AttendanceConcerns | |||
There was a problem hiding this comment.
As this is one concern I think this should just be AttendanceConcern same for the file name so it matches the following:
- Rails autoloading expectations
- ActiveSupport::Concern conventions
- The rails generate concern behaviour
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 | ||
|
|
||
|
|
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Micro detail: the ids method - https://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-ids
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