feat: closes #13578, increase uniquevisitors

on ap pageviews like normal pageviews
This commit is contained in:
Barış Soner Uşaklı
2025-08-05 10:46:10 -04:00
parent 340618d3e0
commit e1423636a5
2 changed files with 14 additions and 9 deletions

View File

@@ -102,8 +102,17 @@ Analytics.pageView = async function (payload) {
local.pageViewsGuest += 1; local.pageViewsGuest += 1;
} }
if (payload.ip) { await incrementUniqueVisitors(payload.ip);
const score = await db.sortedSetScore('ip:recent', payload.ip); };
Analytics.apPageView = async function ({ ip }) {
local.apPageViews += 1;
await incrementUniqueVisitors(ip);
};
async function incrementUniqueVisitors(ip) {
if (ip) {
const score = await db.sortedSetScore('ip:recent', ip);
let record = !score; let record = !score;
if (score) { if (score) {
const today = new Date(); const today = new Date();
@@ -113,14 +122,10 @@ Analytics.pageView = async function (payload) {
if (record) { if (record) {
local.uniquevisitors += 1; local.uniquevisitors += 1;
await db.sortedSetAdd('ip:recent', Date.now(), payload.ip); await db.sortedSetAdd('ip:recent', Date.now(), ip);
} }
} }
}; }
Analytics.apPageView = function () {
local.apPageViews += 1;
};
Analytics.writeData = async function () { Analytics.writeData = async function () {
const today = new Date(); const today = new Date();

View File

@@ -10,7 +10,7 @@ const middleware = module.exports;
middleware.enabled = async (req, res, next) => next(!meta.config.activitypubEnabled ? 'route' : undefined); middleware.enabled = async (req, res, next) => next(!meta.config.activitypubEnabled ? 'route' : undefined);
middleware.pageview = async (req, res, next) => { middleware.pageview = async (req, res, next) => {
analytics.apPageView(); await analytics.apPageView({ ip: req.ip });
next(); next();
}; };