-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eliminate some N+1s #155
Eliminate some N+1s #155
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,11 @@ class ApplicationController < ActionController::Base | |
def current_profile = current_user&.profile | ||
|
||
# TODO: Must change after implementing multi-conference support | ||
def current_conference = Conference.last | ||
def current_conference | ||
@_current_conference ||= Conference.last | ||
end | ||
|
||
def vapid_public_key | ||
Base64.urlsafe_decode64(ENV["VAPID_PUBLIC_KEY"]).bytes.to_json | ||
@_vapid_public_key ||= Base64.urlsafe_decode64(ENV["VAPID_PUBLIC_KEY"]).bytes.to_json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one isn't a big deal but since it's computed every time time main layout renders it seemed worth memoising as well. |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ def show | |
@sessions = SessionQuery.new( | ||
relation: current_user.sessions.where(conference: current_conference), | ||
params: filter_params | ||
).call.includes(:attendees, :location, :speakers, :tags).order(:starts_at) | ||
).call.includes(:location, :tags, speakers: [profile: :image_attachment]).order(:starts_at) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment applies to the two actions amended in The |
||
end | ||
|
||
private | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
</a> | ||
</div> | ||
<div class="w-full mx-2 mb-1 border-b"></div> | ||
<div class="mb-1 text-gray-400 text-nowrap"><%= pluralize(sessions.count, "Session") %></div> | ||
<div class="mb-1 text-gray-400 text-nowrap"><%= pluralize(sessions.length, "Session") %></div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment applies to all similar changes below. Calling |
||
<% end %> | ||
<% sessions.each do |session| %> | ||
<%= render( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ | |
:div, | ||
class: [ | ||
"flex flex-col ml-2", | ||
"max-w-[200px]": session.speakers.count > 1 | ||
"max-w-[200px]": session.speakers.length > 1 | ||
] | ||
) do %> | ||
<h2 class="text-sm italic font-black group-hover:text-red group-focus:text-red"><%= speaker.name %></h2> | ||
|
@@ -71,7 +71,7 @@ | |
<% end %> | ||
|
||
<div class="flex flex-col"> | ||
<% if session.tags.exists? %> | ||
<% if session.tags.present? %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the |
||
<div class="flex flex-wrap w-full gap-2 mb-3"> | ||
<% session.tags.each do |tag| %> | ||
<div class="px-2 py-1 text-xs bg-transparent border rounded-lg border-bluegray-600 text-bluegray-600"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is called a bunch of times per request resulting in a query each time.