mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-29 10:58:19 +03:00
Send max of API users or extension users
This commit is contained in:
@@ -12,28 +12,30 @@ let apiUsersCache = null;
|
|||||||
let lastUserCountCheck = 0;
|
let lastUserCountCheck = 0;
|
||||||
|
|
||||||
module.exports = function getTotalStats (req, res) {
|
module.exports = function getTotalStats (req, res) {
|
||||||
let row = db.prepare('get', "SELECT COUNT(DISTINCT userID) as userCount, COUNT(*) as totalSubmissions, " +
|
let row = db.prepare('get', "SELECT COUNT(DISTINCT userID) as userCount, COUNT(*) as totalSubmissions, " +
|
||||||
"SUM(views) as viewCount, SUM((endTime - startTime) / 60 * views) as minutesSaved FROM sponsorTimes WHERE shadowHidden != 1 AND votes >= 0", []);
|
"SUM(views) as viewCount, SUM((endTime - startTime) / 60 * views) as minutesSaved FROM sponsorTimes WHERE shadowHidden != 1 AND votes >= 0", []);
|
||||||
|
|
||||||
if (row !== undefined) {
|
if (row !== undefined) {
|
||||||
//send this result
|
let extensionUsers = chromeUsersCache + firefoxUsersCache;
|
||||||
res.send({
|
|
||||||
userCount: row.userCount,
|
|
||||||
activeUsers: chromeUsersCache + firefoxUsersCache,
|
|
||||||
apiUsers: apiUsersCache,
|
|
||||||
viewCount: row.viewCount,
|
|
||||||
totalSubmissions: row.totalSubmissions,
|
|
||||||
minutesSaved: row.minutesSaved
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if the cache should be updated (every ~14 hours)
|
//send this result
|
||||||
let now = Date.now();
|
res.send({
|
||||||
if (now - lastUserCountCheck > 5000000) {
|
userCount: row.userCount,
|
||||||
lastUserCountCheck = now;
|
activeUsers: extensionUsers,
|
||||||
|
apiUsers: Math.max(apiUsersCache, extensionUsers),
|
||||||
|
viewCount: row.viewCount,
|
||||||
|
totalSubmissions: row.totalSubmissions,
|
||||||
|
minutesSaved: row.minutesSaved
|
||||||
|
});
|
||||||
|
|
||||||
updateExtensionUsers();
|
// Check if the cache should be updated (every ~14 hours)
|
||||||
}
|
let now = Date.now();
|
||||||
}
|
if (now - lastUserCountCheck > 5000000) {
|
||||||
|
lastUserCountCheck = now;
|
||||||
|
|
||||||
|
updateExtensionUsers();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateExtensionUsers() {
|
function updateExtensionUsers() {
|
||||||
|
|||||||
Reference in New Issue
Block a user