Fixed user page birthday for Wii U and 3DS. Updates the popular community follow count without refreshing the whole cache

This commit is contained in:
Jemma
2024-04-23 19:18:35 -05:00
parent 2bae9c5078
commit 95fab2bae9
5 changed files with 21 additions and 8 deletions

View File

@@ -231,17 +231,30 @@ router.get('/:communityID/:type/more', async function (req, res) {
router.post('/follow', upload.none(), async function (req, res) {
const community = await database.getCommunityByID(req.body.id);
const userContent = await database.getUserContent(req.pid);
const popularCommunities = JSON.parse(await redis.getValue('popularCommunities'));
let updated = false;
if (userContent !== null && userContent.followed_communities.indexOf(community.olive_community_id) === -1) {
community.upFollower();
userContent.addToCommunities(community.olive_community_id);
res.send({ status: 200, id: community.olive_community_id, count: community.followers });
updated = true;
} else if (userContent !== null && userContent.followed_communities.indexOf(community.olive_community_id) !== -1) {
community.downFollower();
userContent.removeFromCommunities(community.olive_community_id);
res.send({ status: 200, id: community.olive_community_id, count: community.followers });
updated = true;
} else {
res.send({ status: 423, id: community.olive_community_id, count: community.followers });
}
if (popularCommunities && updated) {
const index = popularCommunities.findIndex((element) => element.olive_community_id === community.olive_community_id);
if (index !== -1) {
popularCommunities[index].followers = community.followers;
redis.setValue('popularCommunities', JSON.stringify(popularCommunities), 60 * 60);
}
}
});
async function calculateMostPopularCommunities() {

View File

@@ -100,7 +100,7 @@ router.post('/empathy', yeahLimit, async function (req, res) {
} else {
res.send({status: 423, id: post.id, count: post.empathy_count});
}
await redis.removeValue(`${post.pid}-user_page_posts`);
await redis.removeValue(`${post.pid}_user_page_posts`);
});
router.post('/new', postLimit, upload.none(), async function (req, res) {
@@ -163,7 +163,7 @@ router.delete('/:post_id', async function (req, res) {
} else {
res.send('/users/me');
}
await redis.removeValue(`${post.pid}-user_page_posts`);
await redis.removeValue(`${post.pid}_user_page_posts`);
});
router.post('/:post_id/new', postLimit, upload.none(), async function (req, res) {
@@ -295,12 +295,11 @@ async function newPost(req, res) {
if (duplicatePost && req.params.post_id) {
return res.redirect('/posts/' + req.params.post_id.toString());
}
if (document.body === '' && document.painting === '' && document.screenshot === '') {
if (document.body === '' && document.painting === '' && document.screenshot === '' || duplicatePost) {
return res.redirect('/titles/' + community.olive_community_id + '/new');
}
const newPost = new POST(document);
newPost.save();
await redis.removeValue(`${newPost.pid}-user_page_posts`);
if (parentPost) {
parentPost.reply_count = parentPost.reply_count + 1;
parentPost.save();
@@ -312,12 +311,13 @@ async function newPost(req, res) {
user: req.pid,
link: `/posts/${parentPost.id}`
});
await redis.removeValue(`${parentPost.pid}-user_page_posts`);
}
if (parentPost) {
res.redirect('/posts/' + req.params.post_id.toString());
await redis.removeValue(`${parentPost.pid}_user_page_posts`);
} else {
res.redirect('/titles/' + community.olive_community_id + '/new');
await redis.removeValue(`${req.pid}_user_page_posts`);
}
}

View File

@@ -153,7 +153,7 @@ async function userPage(req, res, userID) {
let posts = JSON.parse(await redis.getValue(`${userID}-user_page_posts`));
if (!posts) {
posts = await database.getNumberUserPostsByID(userID, config.post_limit);
await redis.setValue(`${userID}-user_page_posts`, JSON.stringify(posts), 60 * 60 * 1);
await redis.setValue(`${userID}_user_page_posts`, JSON.stringify(posts), 60 * 60 * 1);
}

View File

@@ -45,7 +45,7 @@
<%if(userSettings.birthday_visibility){%>
<span>|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="#ffffff" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"/><line x1="128" y1="88" x2="128" y2="64" fill="none" stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><path d="M128,64c46.2-16,0-56,0-56S80,48,128,64Z" fill="none" stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><path d="M162,126a34,34,0,0,1-68,0" fill="none" stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><path d="M94,126a34,34,0,0,1-33.3,34c-19.1.4-34.7-15.6-34.7-34.7V112A23.9,23.9,0,0,1,50,88H206a23.9,23.9,0,0,1,24,24v13.3c0,19.1-15.6,35.1-34.7,34.7A34,34,0,0,1,162,126" fill="none" stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/><path d="M216,153.3V208a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V153.3" fill="none" stroke="#ffffff" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"/></svg>
<%=moment.utc(pnid.birthday).format("MMM Do")%>
<%=moment.utc(pnid.birthdate || pnid.birthday).format("MMM Do")%>
</span>
<%}%>
<%if(userSettings.game_skill_visibility){%>

View File

@@ -94,7 +94,7 @@
</div>
<div>
<h4><%= lang.user_page.birthday %></h4>
<h4><%if(userSettings.birthday_visibility){%><%=moment.utc(pnid.birthdate).format("MMM Do")%><%}else {%><%= lang.global.private %><%}%></h4>
<h4><%if(userSettings.birthday_visibility){%><%=moment.utc(pnid.birthdate || pnid.birthday).format("MMM Do")%><%}else {%><%= lang.global.private %><%}%></h4>
</div>
<div>
<h4><%= lang.user_page.game_experience %></h4>