mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
perf: only load posts once
This commit is contained in:
@@ -179,12 +179,14 @@ define('forum/topic', [
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let timeoutId = 0;
|
let timeoutId = 0;
|
||||||
|
const postCache = {};
|
||||||
$('[component="topic"]').on('mouseenter', '[component="post"] a, [component="topic/event"] a', async function () {
|
$('[component="topic"]').on('mouseenter', '[component="post"] a, [component="topic/event"] a', async function () {
|
||||||
const link = $(this);
|
const link = $(this);
|
||||||
|
|
||||||
async function renderPost(pid) {
|
async function renderPost(pid) {
|
||||||
const postData = await socket.emit('posts.getPostSummaryByPid', { pid: pid });
|
const postData = postCache[pid] || await socket.emit('posts.getPostSummaryByPid', { pid: pid });
|
||||||
if (postData) {
|
if (postData) {
|
||||||
|
postCache[pid] = postData;
|
||||||
const tooltip = await app.parseAndTranslate('partials/topic/post-preview', { post: postData });
|
const tooltip = await app.parseAndTranslate('partials/topic/post-preview', { post: postData });
|
||||||
tooltip.hide().find('.timeago').timeago();
|
tooltip.hide().find('.timeago').timeago();
|
||||||
tooltip.appendTo($('body')).fadeIn(300);
|
tooltip.appendTo($('body')).fadeIn(300);
|
||||||
|
|||||||
Reference in New Issue
Block a user