db_getUserAverageWpm10 is now not called every time the caret is changed.

This commit is contained in:
jonny-exe 2021-01-10 11:51:42 +01:00
parent 751264c99b
commit 9d4274c53e
2 changed files with 11 additions and 9 deletions

View file

@ -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;
}

View file

@ -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,