mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-31 20:00:07 +01:00
fix: simplify increasePostCount logic by combining methods
This commit is contained in:
@@ -126,7 +126,7 @@ topicsController.get = async function getTopic(req, res, next) {
|
||||
buildBreadcrumbs(topicData),
|
||||
addOldCategory(topicData, userPrivileges),
|
||||
addTags(topicData, req, res, currentPage),
|
||||
incrementViewCount(req, tid),
|
||||
topics.increaseViewCount(req, tid),
|
||||
markAsRead(req, tid),
|
||||
analytics.increment([`pageviews:byCid:${topicData.category.cid}`]),
|
||||
]);
|
||||
@@ -164,19 +164,6 @@ function calculateStartStop(page, postIndex, settings) {
|
||||
return { start: Math.max(0, start), stop: Math.max(0, stop) };
|
||||
}
|
||||
|
||||
async function incrementViewCount(req, tid) {
|
||||
const allow = req.uid > 0 || (meta.config.guestsIncrementTopicViews && req.uid === 0);
|
||||
if (allow) {
|
||||
req.session.tids_viewed = req.session.tids_viewed || {};
|
||||
const now = Date.now();
|
||||
const interval = meta.config.incrementTopicViewsInterval * 60000;
|
||||
if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < now - interval) {
|
||||
await topics.increaseViewCount(tid);
|
||||
req.session.tids_viewed[tid] = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function markAsRead(req, tid) {
|
||||
if (req.loggedIn) {
|
||||
const markedRead = await topics.markAsRead([tid], req.uid);
|
||||
|
||||
Reference in New Issue
Block a user