Skip to content

Node.js based forum software built for the modern web

perf: only load posts once

Barış Soner Uşaklı9fbb3b11efb0
diff --git a/public/src/client/topic.js b/public/src/client/topic.js
index 8127967292..4f32f70777 100644
--- a/public/src/client/topic.js
+++ b/public/src/client/topic.js
@@ -179,12 +179,14 @@ define('forum/topic', [
return;
}
let timeoutId = 0;
+ const postCache = {};
$('[component="topic"]').on('mouseenter', '[component="post"] a, [component="topic/event"] a', async function () {
const link = $(this);
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) {
+ postCache[pid] = postData;
const tooltip = await app.parseAndTranslate('partials/topic/post-preview', { post: postData });
tooltip.hide().find('.timeago').timeago();
tooltip.appendTo($('body')).fadeIn(300);