From d30ed659de70a2cd833a18c02005b5c9a3b84bd8 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 28 Oct 2022 13:49:18 +0300 Subject: Basic profile caching --- vnext/src/api/index.js | 19 ++++++++++++++----- vnext/src/ui/Thread.js | 4 ++-- vnext/src/ui/UserInfo.js | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'vnext/src') diff --git a/vnext/src/api/index.js b/vnext/src/api/index.js index f88695f2..aa0ddc6e 100644 --- a/vnext/src/api/index.js +++ b/vnext/src/api/index.js @@ -213,6 +213,8 @@ export function markReadTracker(msg, visitor) { return `${apiBaseUrl}/api/thread/mark_read/${msg.mid}-${msg.rid || 0}.gif?hash=${visitor.hash}`; } +let profileCache = {}; + /** * Fetch user profile * @@ -220,10 +222,17 @@ export function markReadTracker(msg, visitor) { */ export function fetchUserUri(profileUrl) { return new Promise((resolve, reject) => { - client.get(profileUrl, { - headers: { - 'Accept': 'application/ld+json' - } - }).then(response => resolve(response)).catch(reject); + if (profileCache[profileUrl]) { + resolve(profileCache[profileUrl]); + } else { + client.get(profileUrl, { + headers: { + 'Accept': 'application/ld+json' + } + }).then(response => { + profileCache[profileUrl] = response.data; + resolve(response.data); + }).catch(reject); + } }); } diff --git a/vnext/src/ui/Thread.js b/vnext/src/ui/Thread.js index a290acd7..4982daed 100644 --- a/vnext/src/ui/Thread.js +++ b/vnext/src/ui/Thread.js @@ -53,8 +53,8 @@ function Comment({ msg, draft, visitor, active, setActive, onStartEditing, postC if (isMounted) { setAuthor({ uid: 0, - uname: remote_user.data.preferredUsername, - avatar: remote_user.data.icon && remote_user.data.icon.url, + uname: remote_user.preferredUsername, + avatar: remote_user.icon && remote_user.icon.url, uri: author.uri }); } diff --git a/vnext/src/ui/UserInfo.js b/vnext/src/ui/UserInfo.js index 9a663829..9239c58c 100644 --- a/vnext/src/ui/UserInfo.js +++ b/vnext/src/ui/UserInfo.js @@ -104,8 +104,8 @@ export function UserLink(props) { if (isMounted) { setUser({ uid: 0, - uname: remote_user.data.preferredUsername, - avatar: remote_user.data.icon && remote_user.data.icon.url, + uname: remote_user.preferredUsername, + avatar: remote_user.icon && remote_user.icon.url, uri: userRef.current.uri }); } -- cgit v1.2.3