mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: N+1 query for avatars when searching for users
This commit is contained in:
parent
9724d3bf42
commit
c9969738bf
2 changed files with 3 additions and 10 deletions
|
@ -297,13 +297,6 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.avatar_template(email)
|
|
||||||
user = User.select([:email, :use_uploaded_avatar, :uploaded_avatar_template, :uploaded_avatar_id])
|
|
||||||
.where(email: Email.downcase(email))
|
|
||||||
.first
|
|
||||||
user.avatar_template if user.present?
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.gravatar_template(email)
|
def self.gravatar_template(email)
|
||||||
email_hash = self.email_hash(email)
|
email_hash = self.email_hash(email)
|
||||||
"//www.gravatar.com/avatar/#{email_hash}.png?s={size}&r=pg&d=identicon"
|
"//www.gravatar.com/avatar/#{email_hash}.png?s={size}&r=pg&d=identicon"
|
||||||
|
@ -314,7 +307,7 @@ class User < ActiveRecord::Base
|
||||||
# - self oneboxes in open graph data
|
# - self oneboxes in open graph data
|
||||||
# - emails
|
# - emails
|
||||||
def small_avatar_url
|
def small_avatar_url
|
||||||
template = User.avatar_template(email)
|
template = avatar_template
|
||||||
template.gsub("{size}", "60")
|
template.gsub("{size}", "60")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Search
|
||||||
|
|
||||||
def self.from_user(u)
|
def self.from_user(u)
|
||||||
SearchResult.new(type: :user, id: u.username_lower, title: u.username, url: "/users/#{u.username_lower}").tap do |r|
|
SearchResult.new(type: :user, id: u.username_lower, title: u.username, url: "/users/#{u.username_lower}").tap do |r|
|
||||||
r.avatar_template = User.avatar_template(u.email)
|
r.avatar_template = u.avatar_template
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class Search
|
||||||
def self.from_post(p)
|
def self.from_post(p)
|
||||||
if p.post_number == 1
|
if p.post_number == 1
|
||||||
# we want the topic link when it's the OP
|
# we want the topic link when it's the OP
|
||||||
SearchResult.from_topic(p.topic)
|
SearchResult.from_topic(p.topic)
|
||||||
else
|
else
|
||||||
SearchResult.new(type: :topic, id: p.topic.id, title: p.topic.title, url: p.url)
|
SearchResult.new(type: :topic, id: p.topic.id, title: p.topic.title, url: p.url)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue