mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-09-13 18:16:48 +08:00
db_getUserAverageWpm10 is now not called every time the caret is changed.
This commit is contained in:
parent
751264c99b
commit
9d4274c53e
2 changed files with 11 additions and 9 deletions
19
src/js/db.js
19
src/js/db.js
|
@ -166,7 +166,8 @@ export async function db_getUserAverageWpm10(
|
|||
function cont() {
|
||||
let wpmSum = 0;
|
||||
let count = 0;
|
||||
dbSnapshot.results.forEach((result) => {
|
||||
// You have to use every so you can break out of the loop
|
||||
dbSnapshot.results.every((result) => {
|
||||
if (
|
||||
result.mode == mode &&
|
||||
result.punctuation == punctuation &&
|
||||
|
@ -175,20 +176,22 @@ export async function db_getUserAverageWpm10(
|
|||
) {
|
||||
wpmSum += result.wpm;
|
||||
count++;
|
||||
if (count >= 10) {
|
||||
return Math.round(wpmSum / 10);
|
||||
if (count < 10) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return Math.round(wpmSum / count);
|
||||
}
|
||||
|
||||
let retval;
|
||||
if (dbSnapshot == null || dbSnapshot.results === undefined) {
|
||||
retval = 0;
|
||||
} else {
|
||||
retval = cont();
|
||||
let retval = 0;
|
||||
|
||||
if (dbSnapshot == null) return retval;
|
||||
var dbSnapshotValid = await db_getUserResults();
|
||||
if (dbSnapshotValid === false) {
|
||||
return retval;
|
||||
}
|
||||
retval = cont();
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -3936,7 +3936,6 @@ async function initPaceCaret() {
|
|||
config.difficulty
|
||||
);
|
||||
} else if (config.paceCaret === "average") {
|
||||
await db_getUserResults();
|
||||
wpm = await db_getUserAverageWpm10(
|
||||
config.mode,
|
||||
config.punctuation,
|
||||
|
|
Loading…
Add table
Reference in a new issue