Only call user counter some of the time

This commit is contained in:
Ajay
2022-12-05 16:47:11 -05:00
parent 1202c264aa
commit 4e3753d32c
3 changed files with 6 additions and 2 deletions

View File

@@ -65,6 +65,7 @@ addDefaults(config, {
}
},
userCounterURL: null,
userCounterRatio: 10,
newLeafURLs: null,
maxRewardTimePerSegmentInSeconds: 600,
poiMinimumStartTime: 2,

View File

@@ -6,8 +6,10 @@ import { NextFunction, Request, Response } from "express";
export function userCounter(req: Request, res: Response, next: NextFunction): void {
if (req.method !== "OPTIONS") {
axios.post(`${config.userCounterURL}/api/v1/addIP?hashedIP=${getIP(req)}`)
.catch(() => Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`));
if (Math.random() < 1 / config.userCounterRatio) {
axios.post(`${config.userCounterURL}/api/v1/addIP?hashedIP=${getIP(req)}`)
.catch(() => Logger.debug(`Failing to connect to user counter at: ${config.userCounterURL}`));
}
}
next();

View File

@@ -52,6 +52,7 @@ export interface SBSConfig {
minReputationToSubmitChapter: number;
minReputationToSubmitFiller: number;
userCounterURL?: string;
userCounterRatio: number;
proxySubmission?: string;
behindProxy: string | boolean;
db: string;