mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 15:37:07 +03:00
Add timing trace to set username
This commit is contained in:
@@ -27,6 +27,8 @@ export async function setUsername(req: Request, res: Response): Promise<Response
|
|||||||
return res.sendStatus(200);
|
return res.sendStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const timings = [Date.now()];
|
||||||
|
|
||||||
// remove unicode control characters from username (example: \n, \r, \t etc.)
|
// remove unicode control characters from username (example: \n, \r, \t etc.)
|
||||||
// source: https://en.wikipedia.org/wiki/Control_character#In_Unicode
|
// source: https://en.wikipedia.org/wiki/Control_character#In_Unicode
|
||||||
// eslint-disable-next-line no-control-regex
|
// eslint-disable-next-line no-control-regex
|
||||||
@@ -37,6 +39,8 @@ export async function setUsername(req: Request, res: Response): Promise<Response
|
|||||||
return res.sendStatus(400);
|
return res.sendStatus(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timings.push(Date.now());
|
||||||
|
|
||||||
if (adminUserIDInput != undefined) {
|
if (adminUserIDInput != undefined) {
|
||||||
//this is the admin controlling the other users account, don't hash the controling account's ID
|
//this is the admin controlling the other users account, don't hash the controling account's ID
|
||||||
adminUserIDInput = await getHashCache(adminUserIDInput);
|
adminUserIDInput = await getHashCache(adminUserIDInput);
|
||||||
@@ -50,16 +54,22 @@ export async function setUsername(req: Request, res: Response): Promise<Response
|
|||||||
userID = await getHashCache(userID);
|
userID = await getHashCache(userID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timings.push(Date.now());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const row = await db.prepare("get", `SELECT count(*) as "userCount" FROM "userNames" WHERE "userID" = ? AND "locked" = 1`, [userID]);
|
const row = await db.prepare("get", `SELECT count(*) as "userCount" FROM "userNames" WHERE "userID" = ? AND "locked" = 1`, [userID]);
|
||||||
if (adminUserIDInput === undefined && row.userCount > 0) {
|
if (adminUserIDInput === undefined && row.userCount > 0) {
|
||||||
return res.sendStatus(200);
|
return res.sendStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timings.push(Date.now());
|
||||||
|
|
||||||
const shadowBanRow = await db.prepare("get", `SELECT count(*) as "userCount" FROM "shadowBannedUsers" WHERE "userID" = ? LIMIT 1`, [userID]);
|
const shadowBanRow = await db.prepare("get", `SELECT count(*) as "userCount" FROM "shadowBannedUsers" WHERE "userID" = ? LIMIT 1`, [userID]);
|
||||||
if (adminUserIDInput === undefined && shadowBanRow.userCount > 0) {
|
if (adminUserIDInput === undefined && shadowBanRow.userCount > 0) {
|
||||||
return res.sendStatus(200);
|
return res.sendStatus(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timings.push(Date.now());
|
||||||
}
|
}
|
||||||
catch (error) /* istanbul ignore next */ {
|
catch (error) /* istanbul ignore next */ {
|
||||||
Logger.error(error as string);
|
Logger.error(error as string);
|
||||||
@@ -72,6 +82,8 @@ export async function setUsername(req: Request, res: Response): Promise<Response
|
|||||||
const locked = adminUserIDInput === undefined ? 0 : 1;
|
const locked = adminUserIDInput === undefined ? 0 : 1;
|
||||||
let oldUserName = "";
|
let oldUserName = "";
|
||||||
|
|
||||||
|
timings.push(Date.now());
|
||||||
|
|
||||||
if (row?.userName !== undefined) {
|
if (row?.userName !== undefined) {
|
||||||
//already exists, update this row
|
//already exists, update this row
|
||||||
oldUserName = row.userName;
|
oldUserName = row.userName;
|
||||||
@@ -85,9 +97,14 @@ export async function setUsername(req: Request, res: Response): Promise<Response
|
|||||||
await db.prepare("run", `INSERT INTO "userNames"("userID", "userName", "locked") VALUES(?, ?, ?)`, [userID, userName, locked]);
|
await db.prepare("run", `INSERT INTO "userNames"("userID", "userName", "locked") VALUES(?, ?, ?)`, [userID, userName, locked]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timings.push(Date.now());
|
||||||
|
|
||||||
await logUserNameChange(userID, userName, oldUserName, adminUserIDInput !== undefined);
|
await logUserNameChange(userID, userName, oldUserName, adminUserIDInput !== undefined);
|
||||||
|
|
||||||
return res.sendStatus(200);
|
timings.push(Date.now());
|
||||||
|
|
||||||
|
|
||||||
|
return res.status(200).send(timings.join(", "));
|
||||||
} catch (err) /* istanbul ignore next */ {
|
} catch (err) /* istanbul ignore next */ {
|
||||||
Logger.error(err as string);
|
Logger.error(err as string);
|
||||||
return res.sendStatus(500);
|
return res.sendStatus(500);
|
||||||
|
|||||||
Reference in New Issue
Block a user