Only count users when asked

This commit is contained in:
Ajay Ramachandran 2021-03-11 18:40:09 -05:00
parent 0c4e4af228
commit 4168733825

View file

@ -14,7 +14,9 @@ let apiUsersCache = 0;
let lastUserCountCheck = 0;
export async function getTotalStats(req: Request, res: Response) {
let row = await db.prepare('get', `SELECT COUNT(DISTINCT "userID") as "userCount", COUNT(*) as "totalSubmissions",
const userCountQuery = `(SELECT COUNT(*) FROM (SELECT DISTINCT "userID" from "sponsorTimes") t) "userCount",`;
let row = await db.prepare('get', `SELECT ${req.query.countContributingUsers ? userCountQuery : ""} COUNT(*) as "totalSubmissions",
SUM("views") as "viewCount", SUM(("endTime" - "startTime") / 60 * "views") as "minutesSaved" FROM "sponsorTimes" WHERE "shadowHidden" != 1 AND "votes" >= 0`, []);
if (row !== undefined) {