mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 18:22:04 +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:
@ -435,16 +435,9 @@ QUnit.test("Quotes", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("Mentions", assert => {
|
||||
const alwaysTrue = {
|
||||
mentionLookup: function() {
|
||||
return "user";
|
||||
}
|
||||
};
|
||||
|
||||
assert.cookedOptions(
|
||||
assert.cooked(
|
||||
"Hello @sam",
|
||||
alwaysTrue,
|
||||
'<p>Hello <a class="mention" href="/u/sam">@sam</a></p>',
|
||||
'<p>Hello <span class="mention">@sam</span></p>',
|
||||
"translates mentions to links"
|
||||
);
|
||||
|
||||
@ -454,9 +447,8 @@ QUnit.test("Mentions", assert => {
|
||||
"it doesn't do mentions within links"
|
||||
);
|
||||
|
||||
assert.cookedOptions(
|
||||
assert.cooked(
|
||||
"[@codinghorror](https://twitter.com/codinghorror)",
|
||||
alwaysTrue,
|
||||
'<p><a href="https://twitter.com/codinghorror">@codinghorror</a></p>',
|
||||
"it doesn't do link mentions within links"
|
||||
);
|
||||
@ -557,17 +549,9 @@ QUnit.test("Mentions", assert => {
|
||||
"handles mentions separated by a slash."
|
||||
);
|
||||
|
||||
assert.cookedOptions(
|
||||
"@eviltrout",
|
||||
alwaysTrue,
|
||||
'<p><a class="mention" href="/u/eviltrout">@eviltrout</a></p>',
|
||||
"it doesn't onebox mentions"
|
||||
);
|
||||
|
||||
assert.cookedOptions(
|
||||
assert.cooked(
|
||||
"<small>a @sam c</small>",
|
||||
alwaysTrue,
|
||||
'<p><small>a <a class="mention" href="/u/sam">@sam</a> c</small></p>',
|
||||
'<p><small>a <span class="mention">@sam</span> c</small></p>',
|
||||
"it allows mentions within HTML tags"
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user