mirror of
https://github.com/discourse/discourse.git
synced 2025-09-08 12:06:51 +08:00
PERF: Move mention lookups out of the V8 context. (#6640)
We were looking up each mention one by one without any form of caching and that results in a problem somewhat similar to an N+1. When we have to do alot of DB lookups, it also increased the time spent in the V8 context which may eventually lead to a timeout. The change here makes it such that mention lookups only does a single DB query per post that happens outside of the V8 context.
This commit is contained in:
parent
596e09aaf9
commit
c5a70eca6e
7 changed files with 125 additions and 75 deletions
|
@ -220,18 +220,37 @@ describe PrettyText do
|
|||
expect(PrettyText.cook("hi\n@.s.s")).to eq("<p>hi<br>\n@.s.s</p>")
|
||||
end
|
||||
|
||||
it "can handle mention with hyperlinks" do
|
||||
Fabricate(:user, username: "sam")
|
||||
expect(PrettyText.cook("hi @sam! hi")).to match_html '<p>hi <a class="mention" href="/u/sam">@sam</a>! hi</p>'
|
||||
expect(PrettyText.cook("hi\n@sam.")).to eq("<p>hi<br>\n<a class=\"mention\" href=\"/u/sam\">@sam</a>.</p>")
|
||||
end
|
||||
it "handles user and group mentions correctly" do
|
||||
['user', 'user2'].each do |username |
|
||||
Fabricate(:user, username: username)
|
||||
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>}
|
||||
)
|
||||
[
|
||||
[
|
||||
'hi @user! @user2 hi',
|
||||
'<p>hi <a class="mention" href="/u/user">@user</a>! <a class="mention" href="/u/user2">@user2</a> hi</p>'
|
||||
],
|
||||
[
|
||||
"hi\n@user. @#{group.name} @somemention",
|
||||
%Q|<p>hi<br>\n<a class="mention" href="/u/user">@user</a>. <a class="mention-group" href="/groups/#{group.name}">@#{group.name}</a> <span class="mention">@somemention</span></p>|
|
||||
]
|
||||
].each do |input, expected|
|
||||
expect(PrettyText.cook(input)).to eq(expected)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when mentions are disabled' do
|
||||
before do
|
||||
SiteSetting.enable_mentions = false
|
||||
end
|
||||
|
||||
it 'should not convert mentions to links' do
|
||||
user = Fabricate(:user)
|
||||
|
||||
expect(PrettyText.cook('hi @user')).to eq('<p>hi @user</p>')
|
||||
end
|
||||
end
|
||||
|
||||
it "can handle mentions inside a hyperlink" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue