mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-11 13:57:28 +08:00
now only pulling account data when the user really needs it
This commit is contained in:
parent
6e1a9b46b3
commit
28a2f09b60
2 changed files with 71 additions and 26 deletions
|
|
@ -264,6 +264,9 @@ firebase.auth().onAuthStateChanged(function (user) {
|
|||
) {
|
||||
config.resultFilters = defaultAccountFilters;
|
||||
}
|
||||
if ($(".pageLogin").hasClass("active")) {
|
||||
changePage("account");
|
||||
}
|
||||
accountIconLoading(false);
|
||||
updateFilterTags();
|
||||
updateCommandsTagsList();
|
||||
|
|
@ -525,7 +528,7 @@ function updateFilterTags() {
|
|||
"hidden"
|
||||
);
|
||||
}
|
||||
showActiveFilters();
|
||||
// showActiveFilters();
|
||||
}
|
||||
|
||||
function toggleFilter(group, filter) {
|
||||
|
|
@ -739,7 +742,7 @@ function showActiveFilters() {
|
|||
|
||||
$(".pageAccount .group.chart .above").html(chartString);
|
||||
|
||||
refreshAccountPage();
|
||||
// refreshAccountPage();
|
||||
}
|
||||
|
||||
function showChartPreloader() {
|
||||
|
|
@ -1013,10 +1016,19 @@ function loadMoreLines() {
|
|||
}
|
||||
}
|
||||
|
||||
function showResultLoadProgress(num, outOf) {
|
||||
let percent = (num / outOf) * 100;
|
||||
$(".pageAccount .preloader .loadingBar .bar").css({ width: percent + "%" });
|
||||
console.log(percent);
|
||||
console.log(`${num}/${outOf}`);
|
||||
}
|
||||
|
||||
let totalSecondsFiltered = 0;
|
||||
|
||||
function refreshAccountPage() {
|
||||
function cont() {
|
||||
showActiveFilters();
|
||||
|
||||
refreshThemeColorObject();
|
||||
|
||||
let chartData = [];
|
||||
|
|
@ -1394,15 +1406,16 @@ function refreshAccountPage() {
|
|||
swapElements($(".pageAccount .preloader"), $(".pageAccount .content"), 250);
|
||||
}
|
||||
|
||||
if (dbSnapshot === null) {
|
||||
// console.log('no db snap');
|
||||
// db_getUserResults().then(data => {
|
||||
// if(!data) return;
|
||||
// dbSnapshot = data;
|
||||
// cont();
|
||||
// })
|
||||
if (dbSnapshot.results === undefined) {
|
||||
db_getUserResults().then((d) => {
|
||||
if (d) {
|
||||
cont();
|
||||
} else {
|
||||
console.log("something went wrong");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// console.log('using db snap');
|
||||
console.log("using db snap");
|
||||
cont();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ async function db_getUserSnapshot() {
|
|||
let user = firebase.auth().currentUser;
|
||||
if (user == null) return false;
|
||||
let snap = {
|
||||
results: [],
|
||||
results: undefined,
|
||||
personalBests: {},
|
||||
tags: [],
|
||||
};
|
||||
|
|
@ -21,21 +21,21 @@ async function db_getUserSnapshot() {
|
|||
// })
|
||||
// })
|
||||
try {
|
||||
await db
|
||||
.collection(`users/${user.uid}/results/`)
|
||||
.orderBy("timestamp", "desc")
|
||||
.get()
|
||||
.then((data) => {
|
||||
// console.log('getting data from db!');
|
||||
data.docs.forEach((doc) => {
|
||||
let result = doc.data();
|
||||
result.id = doc.id;
|
||||
snap.results.push(result);
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
// await db
|
||||
// .collection(`users/${user.uid}/results/`)
|
||||
// .orderBy("timestamp", "desc")
|
||||
// .get()
|
||||
// .then((data) => {
|
||||
// // console.log('getting data from db!');
|
||||
// data.docs.forEach((doc) => {
|
||||
// let result = doc.data();
|
||||
// result.id = doc.id;
|
||||
// snap.results.push(result);
|
||||
// });
|
||||
// })
|
||||
// .catch((e) => {
|
||||
// throw e;
|
||||
// });
|
||||
await db
|
||||
.collection(`users/${user.uid}/tags/`)
|
||||
.get()
|
||||
|
|
@ -79,6 +79,38 @@ async function db_getUserSnapshot() {
|
|||
return dbSnapshot;
|
||||
}
|
||||
|
||||
async function db_getUserResults() {
|
||||
let user = firebase.auth().currentUser;
|
||||
if (user == null) return false;
|
||||
if (dbSnapshot.results !== undefined) {
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
return await db
|
||||
.collection(`users/${user.uid}/results/`)
|
||||
.orderBy("timestamp", "desc")
|
||||
.get()
|
||||
.then((data) => {
|
||||
dbSnapshot.results = [];
|
||||
let len = data.docs.length;
|
||||
data.docs.forEach((doc, index) => {
|
||||
showResultLoadProgress(index + 1, len);
|
||||
let result = doc.data();
|
||||
result.id = doc.id;
|
||||
dbSnapshot.results.push(result);
|
||||
});
|
||||
return true;
|
||||
})
|
||||
.catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function db_getUserHighestWpm(
|
||||
mode,
|
||||
mode2,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue