Skip to content

Commit

Permalink
Optimize events#show page (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienpoly authored Jan 15, 2025
1 parent 789070d commit a0403f6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def show
@event.talks_in_running_order.order(date: :asc)
end

event_talks = event_talks.includes(:speakers, :parent_talk, child_talks: :speakers)

if params[:q].present?
talks = event_talks.pagy_search(params[:q])
@pagy, @talks = pagy_meilisearch(talks, limit: 21)
Expand Down
8 changes: 5 additions & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ def held_in_sentence
end

def description
return @description if @description.present?

keynotes = keynote_speakers.any? ? %(, including keynotes by #{keynote_speakers.map(&:name).to_sentence}) : ""

<<~DESCRIPTION
@description = <<~DESCRIPTION
#{organisation.name} is a #{organisation.frequency} #{organisation.kind}#{held_in_sentence} and features #{talks.size} #{"talk".pluralize(talks.size)} from various speakers#{keynotes}.
DESCRIPTION
end
Expand Down Expand Up @@ -269,13 +271,13 @@ def location
end

def start_date
static_metadata.start_date.present? ? static_metadata.start_date : talks.minimum(:date)
@start_date ||= static_metadata.start_date.present? ? static_metadata.start_date : talks.minimum(:date)
rescue => _e
talks.minimum(:date)
end

def end_date
static_metadata.end_date.present? ? static_metadata.end_date : talks.maximum(:date)
@end_date ||= static_metadata.end_date.present? ? static_metadata.end_date : talks.maximum(:date)
rescue => _e
talks.maximum(:date)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/watched_talk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
# index_watched_talks_on_user_id (user_id)
#
class WatchedTalk < ApplicationRecord
belongs_to :user, default: -> { Current.user }
belongs_to :user, default: -> { Current.user }, touch: true
belongs_to :talk
end
8 changes: 1 addition & 7 deletions app/views/talks/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
<% end %>
</div>

<% if signed_in? %>
<% cache_key = [@talk, Current.user, @talk.watched_talks.where(user: Current.user)] %>
<% else %>
<% cache_key = [@talk] %>
<% end %>

<%= turbo_frame_tag "talk", target: "_top", data: {turbo_action: "advance"} do %>
<% cache cache_key do %>
<% cache [@talk, Current.user].compact do %>
<%= render partial: "talks/talk", locals: {talk: @talk} %>
<% end %>
<% end %>
Expand Down

0 comments on commit a0403f6

Please sign in to comment.