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:
Guo Xiang Tan
2018-11-22 14:28:48 +08:00
committed by GitHub
parent 596e09aaf9
commit c5a70eca6e
7 changed files with 125 additions and 75 deletions

View File

@ -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"
);
});