From 9fbb3b11efb0dfca1255058965c5526902b115cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 1 Nov 2021 18:22:39 -0400 Subject: [PATCH] perf: only load posts once --- public/src/client/topic.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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);