Skip to content

Commit

Permalink
fix: #11756, fix unique visitor stats in acp table
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Jun 26, 2023
1 parent 2514aac commit 638e098
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/analytics.js
Expand Up @@ -237,23 +237,26 @@ Analytics.getDailyStatsForSet = async function (set, day, numDays) {
set = `analytics:${set}`;
}

const daysArr = [];
day = new Date(day);
// set the date to tomorrow, because getHourlyStatsForSet steps *backwards* 24 hours to sum up the values
day.setDate(day.getDate() + 1);
day.setHours(0, 0, 0, 0);

while (numDays > 0) {
/* eslint-disable no-await-in-loop */
async function getHourlyStats(hour) {
const dayData = await Analytics.getHourlyStatsForSet(
set,
day.getTime() - (1000 * 60 * 60 * 24 * (numDays - 1)),
hour,
24
);
daysArr.push(dayData.reduce((cur, next) => cur + next));
return dayData.reduce((cur, next) => cur + next);
}
const hours = [];
while (numDays > 0) {
hours.push(day.getTime() - (1000 * 60 * 60 * 24 * (numDays - 1)));
numDays -= 1;
}
return daysArr;

return await Promise.all(hours.map(getHourlyStats));
};

Analytics.getUnwrittenPageviews = function () {
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/admin/dashboard.js
Expand Up @@ -128,12 +128,13 @@ async function getStats() {
}

let results = await Promise.all([
getStatsForSet('ip:recent', 'uniqueIPCount'),
getStatsFromAnalytics('uniquevisitors', 'uniqueIPCount'),
getStatsFromAnalytics('logins', 'loginCount'),
getStatsForSet('users:joindate', 'userCount'),
getStatsForSet('posts:pid', 'postCount'),
getStatsForSet('topics:tid', 'topicCount'),
]);

results[0].name = '[[admin/dashboard:unique-visitors]]';

results[1].name = '[[admin/dashboard:logins]]';
Expand Down

0 comments on commit 638e098

Please sign in to comment.