mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +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:
@ -1,32 +1,12 @@
|
||||
function addMention(buffer, matches, state) {
|
||||
let username = matches[1] || matches[2];
|
||||
let { getURL, mentionLookup, formatUsername } = state.md.options.discourse;
|
||||
|
||||
let type = mentionLookup && mentionLookup(username);
|
||||
|
||||
let tag = "a";
|
||||
let tag = "span";
|
||||
let className = "mention";
|
||||
let href = null;
|
||||
|
||||
if (type === "user") {
|
||||
href = getURL("/u/") + username.toLowerCase();
|
||||
} else if (type === "group") {
|
||||
href = getURL("/groups/") + username;
|
||||
className = "mention-group";
|
||||
} else {
|
||||
tag = "span";
|
||||
}
|
||||
|
||||
let token = new state.Token("mention_open", tag, 1);
|
||||
token.attrs = [["class", className]];
|
||||
if (href) {
|
||||
token.attrs.push(["href", href]);
|
||||
}
|
||||
|
||||
buffer.push(token);
|
||||
if (formatUsername) {
|
||||
username = formatUsername(username);
|
||||
}
|
||||
|
||||
token = new state.Token("text", "", 0);
|
||||
token.content = "@" + username;
|
||||
|
Reference in New Issue
Block a user