PERF: Try to match users before groups.
User mentions are more common than group mentions so this will allow us to avoid an extra query.
This commit is contained in:
parent
44d7249a17
commit
45f299dfdd
|
@ -41,8 +41,8 @@ module PrettyText
|
|||
|
||||
def mention_lookup(name)
|
||||
return false if name.blank?
|
||||
return "group" if Group.exists?(name: name)
|
||||
return "user" if User.exists?(username_lower: name.downcase)
|
||||
return "group" if Group.exists?(name: name)
|
||||
end
|
||||
|
||||
def category_hashtag_lookup(category_slug)
|
||||
|
|
|
@ -226,6 +226,14 @@ describe PrettyText do
|
|||
expect(PrettyText.cook("hi\n@sam.")).to eq("<p>hi<br>\n<a class=\"mention\" href=\"/u/sam\">@sam</a>.</p>")
|
||||
end
|
||||
|
||||
it "can handle group mention" do
|
||||
group = Fabricate(:group)
|
||||
|
||||
expect(PrettyText.cook("hi @#{group.name}! hi")).to match_html(
|
||||
%Q{<p>hi <a class="mention-group" href="/groups/#{group.name}">@#{group.name}</a>! hi</p>}
|
||||
)
|
||||
end
|
||||
|
||||
it "can handle mentions inside a hyperlink" do
|
||||
expect(PrettyText.cook("<a> @inner</a> ")).to match_html '<p><a> @inner</a></p>'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue