I spelt Milliseconds wrong...

This commit is contained in:
zkldi
2021-11-11 02:01:34 +00:00
parent 996d14519a
commit c313f21aef
10 changed files with 34 additions and 34 deletions
+2 -2
View File
@@ -40,7 +40,7 @@ import {
UserMilestoneDocument,
UserSettings,
} from "tachi-common";
import { GetMilisecondsSince } from "utils/misc";
import { GetMillisecondsSince } from "utils/misc";
const logger = CreateLogCtx(__filename);
@@ -63,7 +63,7 @@ export const monkDB = monk(`${Environment.mongoUrl}/${dbName}`, {
/* istanbul ignore next */
monkDB
.then(() => {
logger.info(`Database connection successful: took ${GetMilisecondsSince(dbtime)}ms`, {
logger.info(`Database connection successful: took ${GetMillisecondsSince(dbtime)}ms`, {
bootInfo: true,
});
})
+2 -2
View File
@@ -2,7 +2,7 @@ import { ONE_MINUTE } from "lib/constants/time";
import CreateLogCtx from "lib/logger/logger";
import { Environment } from "lib/setup/config";
import redis from "redis";
import { GetMilisecondsSince } from "utils/misc";
import { GetMillisecondsSince } from "utils/misc";
const logger = CreateLogCtx(__filename);
@@ -27,7 +27,7 @@ function EmitCritical() {
const ref = setTimeout(EmitCritical, ONE_MINUTE * 2);
RedisClient.on("connect", () => {
logger.info(`Connected to Redis. Took ${GetMilisecondsSince(startConnect)}ms`, {
logger.info(`Connected to Redis. Took ${GetMillisecondsSince(startConnect)}ms`, {
bootInfo: true,
});
+2 -2
View File
@@ -2,7 +2,7 @@ import { UserGameStats, UserGameStatsSnapshot } from "tachi-common";
import db from "external/mongo/db";
import CreateLogCtx from "lib/logger/logger";
import { GetUsersRanking } from "utils/user";
import { GetMilisecondsSince } from "utils/misc";
import { GetMillisecondsSince } from "utils/misc";
const logger = CreateLogCtx(__filename);
@@ -70,7 +70,7 @@ export async function UGSSnapshot() {
logger.info(
`Successfully snapshotted all data as of ${new Date(
currentTime
).toString()}. Took ${GetMilisecondsSince(timeStart)} ms.`
).toString()}. Took ${GetMillisecondsSince(timeStart)} ms.`
);
} catch (err) {
// if we panic, we need to revert whatever we did.
+1 -1
View File
@@ -200,7 +200,7 @@ export default class DiscordTransport extends Transport {
// It's possible that messages here could all get stuck in an
// awful loop, so we have a tuning off parameter.
// The scaleRetryDebouncer will get squared every call,
// so the initial request takes 2 * (generally 1milisecond),
// so the initial request takes 2 * (generally 1milliseconds),
// then following requests will take even longer...
// It's possible this might blow up in our face.
// We'll have to see. - zkldi 2021/09/17
@@ -146,7 +146,7 @@ export function CalculateESDForGame(
/**
* Parses and validates a date from a string.
* @returns Miliseconds from the unix epoch, or null if the initial argument was null or undefined.
* @returns Millisecondss from the unix epoch, or null if the initial argument was null or undefined.
*/
export function ParseDateFromString(str: string | undefined | null): number | null {
if (!str) {
@@ -12,7 +12,7 @@ import { KtLogger } from "lib/logger/logger";
import { ImportAllIterableData } from "./score-importing/score-importing";
import { CreateImportLoggerAndID } from "./common/import-logger";
import { CreateSessions } from "./sessions/sessions";
import { GetMilisecondsSince } from "utils/misc";
import { GetMillisecondsSince } from "utils/misc";
import { ProcessPBs } from "./pb/process-pbs";
import { UpdateUsersGamePlaytypeStats } from "./user-game-stats/update-ugs";
import db from "external/mongo/db";
@@ -48,7 +48,7 @@ export default async function ScoreImportMain<D, C>(
//
// Under normal circumstances, there is no scenario where a user would have two ongoing
// imports at the same time - even if they were using single-score imports on a 5 second
// chart, as each score import takes only around ~10-15miliseconds.
// chart, as each score import takes only around ~10-15millisecondss.
throw new ScoreImportFatalError(409, "This user already has an ongoing import.");
}
@@ -73,9 +73,9 @@ export default async function ScoreImportMain<D, C>(
const parseTimeStart = process.hrtime.bigint();
const { iterable, context, game, classHandler } = await InputParser(logger);
const parseTime = GetMilisecondsSince(parseTimeStart);
const parseTime = GetMillisecondsSince(parseTimeStart);
logger.debug(`Parsing took ${parseTime} miliseconds.`);
logger.debug(`Parsing took ${parseTime} millisecondss.`);
// We have to cast here due to typescript generic confusions. This is guaranteed` to be correct.
const ConverterFunction = Converters[importType] as unknown as ConverterFunction<D, C>;
@@ -93,10 +93,10 @@ export default async function ScoreImportMain<D, C>(
logger
);
const importTime = GetMilisecondsSince(importTimeStart);
const importTime = GetMillisecondsSince(importTimeStart);
const importTimeRel = importTime / importInfo.length;
logger.debug(`Importing took ${importTime} miliseconds. (${importTimeRel}ms/doc)`);
logger.debug(`Importing took ${importTime} millisecondss. (${importTimeRel}ms/doc)`);
// Steps 3-8 are handled inside here.
// This was moved inside here so the score de-orphaning process
@@ -203,11 +203,11 @@ export async function HandlePostImportSteps(
const importParseTimeStart = process.hrtime.bigint();
const { scorePlaytypeMap, errors, scoreIDs, chartIDs } = ParseImportInfo(importInfo);
const importParseTime = GetMilisecondsSince(importParseTimeStart);
const importParseTime = GetMillisecondsSince(importParseTimeStart);
const importParseTimeRel = importParseTime / importInfo.length;
logger.debug(
`Import Parsing took ${importParseTime} miliseconds. (${importParseTimeRel}ms/doc)`
`Import Parsing took ${importParseTime} millisecondss. (${importParseTimeRel}ms/doc)`
);
// --- 4. Sessions ---
@@ -216,10 +216,10 @@ export async function HandlePostImportSteps(
const sessionTimeStart = process.hrtime.bigint();
const sessionInfo = await CreateSessions(user.id, importType, game, scorePlaytypeMap, logger);
const sessionTime = GetMilisecondsSince(sessionTimeStart);
const sessionTime = GetMillisecondsSince(sessionTimeStart);
const sessionTimeRel = sessionTime / sessionInfo.length;
logger.debug(`Session Processing took ${sessionTime} miliseconds (${sessionTimeRel}ms/doc).`);
logger.debug(`Session Processing took ${sessionTime} millisecondss (${sessionTimeRel}ms/doc).`);
// --- 5. PersonalBests ---
// We want to keep an updated reference of a users best score on a given chart.
@@ -228,10 +228,10 @@ export async function HandlePostImportSteps(
const pbTimeStart = process.hrtime.bigint();
await ProcessPBs(user.id, chartIDs, logger);
const pbTime = GetMilisecondsSince(pbTimeStart);
const pbTime = GetMillisecondsSince(pbTimeStart);
const pbTimeRel = pbTime / chartIDs.size;
logger.debug(`PB Processing took ${pbTime} miliseconds (${pbTimeRel}ms/doc)`);
logger.debug(`PB Processing took ${pbTime} millisecondss (${pbTimeRel}ms/doc)`);
const playtypes = Object.keys(scorePlaytypeMap) as Playtypes[Game][];
@@ -240,27 +240,27 @@ export async function HandlePostImportSteps(
const ugsTimeStart = process.hrtime.bigint();
const classDeltas = await UpdateUsersGameStats(game, playtypes, user.id, classHandler, logger);
const ugsTime = GetMilisecondsSince(ugsTimeStart);
const ugsTime = GetMillisecondsSince(ugsTimeStart);
logger.debug(`UGS Processing took ${ugsTime} miliseconds.`);
logger.debug(`UGS Processing took ${ugsTime} millisecondss.`);
// --- 7. Goals ---
// Evaluate and update the users goals. This returns information about goals that have changed.
const goalTimeStart = process.hrtime.bigint();
const goalInfo = await GetAndUpdateUsersGoals(game, user.id, chartIDs, logger);
const goalTime = GetMilisecondsSince(goalTimeStart);
const goalTime = GetMillisecondsSince(goalTimeStart);
logger.debug(`Goal Processing took ${goalTime} miliseconds.`);
logger.debug(`Goal Processing took ${goalTime} millisecondss.`);
// --- 8. Milestones ---
// Evaluate and update the users milestones. This returns...
const milestoneTimeStart = process.hrtime.bigint();
const milestoneInfo = await UpdateUsersMilestones(goalInfo, game, playtypes, user.id, logger);
const milestoneTime = GetMilisecondsSince(milestoneTimeStart);
const milestoneTime = GetMillisecondsSince(milestoneTimeStart);
logger.debug(`Milestone Processing took ${milestoneTime} miliseconds.`);
logger.debug(`Milestone Processing took ${milestoneTime} millisecondss.`);
return {
classDeltas,
@@ -380,7 +380,7 @@ t.test("#ParserFn", (t) => {
fn,
new ScoreImportFatalError(
400,
"Invalid BATCH-MANUAL: scores[0].timeAchieved | Expected a number greater than 1 Trillion - did you pass unix seconds instead of miliseconds? | Received string [string]."
"Invalid BATCH-MANUAL: scores[0].timeAchieved | Expected a number greater than 1 Trillion - did you pass unix seconds instead of millisecondss? | Received string [string]."
)
);
@@ -395,7 +395,7 @@ t.test("#ParserFn", (t) => {
fn2,
new ScoreImportFatalError(
400,
"Invalid BATCH-MANUAL: scores[0].timeAchieved | Expected a number greater than 1 Trillion - did you pass unix seconds instead of miliseconds? | Received 1620768609.637 [number]."
"Invalid BATCH-MANUAL: scores[0].timeAchieved | Expected a number greater than 1 Trillion - did you pass unix seconds instead of millisecondss? | Received 1620768609.637 [number]."
),
"Should throw if timeAchieved is less than 10_000_000_000."
);
@@ -138,7 +138,7 @@ const PR_BatchManualScore = (game: Game, playtype: Playtypes[Game]): PrudenceSch
timeAchieved: optNull(
(self) =>
(typeof self === "number" && self > 1_000_000_000_000) ||
"Expected a number greater than 1 Trillion - did you pass unix seconds instead of miliseconds?"
"Expected a number greater than 1 Trillion - did you pass unix seconds instead of millisecondss?"
),
judgements: optNull((self) => {
if (typeof self !== "object" || self === null) {
+3 -3
View File
@@ -1,8 +1,8 @@
import t from "tap";
import { GetMilisecondsSince, IsValidURL } from "./misc";
import { GetMillisecondsSince, IsValidURL } from "./misc";
t.test("#GetMilisecondsSince", (t) => {
const time = GetMilisecondsSince(10n);
t.test("#GetMillisecondssSince", (t) => {
const time = GetMillisecondsSince(10n);
t.ok(typeof time === "number" && time > 0, "Should return a number greater than 0.");
t.end();
+2 -2
View File
@@ -18,10 +18,10 @@ export function EscapeStringRegexp(string: string) {
}
/**
* Takes a process.hrtime.bigint(), and returns the miliseconds elapsed since it.
* Takes a process.hrtime.bigint(), and returns the millisecondss elapsed since it.
* This function will not work if more than 100(ish) days have passed since the first reference.
*/
export function GetMilisecondsSince(ref: bigint) {
export function GetMillisecondsSince(ref: bigint) {
return Number(process.hrtime.bigint() - ref) / 1e6;
}