mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-28 19:08:32 +08:00
refactored how local and snapshot configs are compared
This commit is contained in:
parent
8425a2df3a
commit
0ef0a50381
1 changed files with 11 additions and 43 deletions
|
|
@ -150,51 +150,19 @@ export async function getDataAndInit(): Promise<boolean> {
|
|||
true
|
||||
);
|
||||
}
|
||||
if (!UpdateConfig.localStorageConfig && snapshot.config) {
|
||||
console.log("no local config, applying db");
|
||||
|
||||
const areConfigsEqual =
|
||||
JSON.stringify(Config) === JSON.stringify(snapshot.config);
|
||||
|
||||
if (
|
||||
snapshot.config &&
|
||||
(!UpdateConfig.localStorageConfig || !areConfigsEqual)
|
||||
) {
|
||||
console.log(
|
||||
"no local config or local and db configs are different - applying db"
|
||||
);
|
||||
UpdateConfig.apply(snapshot.config);
|
||||
UpdateConfig.saveFullConfigToLocalStorage(true);
|
||||
} else if (snapshot.config !== undefined) {
|
||||
//loading db config, keep for now
|
||||
let configsDifferent = false;
|
||||
Object.keys(Config).forEach((ke) => {
|
||||
const key = ke as keyof typeof Config;
|
||||
if (configsDifferent) return;
|
||||
try {
|
||||
if (key !== "resultFilters") {
|
||||
if (Array.isArray(Config[key])) {
|
||||
(Config[key] as string[]).forEach((arrval, index) => {
|
||||
const arrayValue = (
|
||||
snapshot?.config?.[key] as
|
||||
| string[]
|
||||
| MonkeyTypes.QuoteLength[]
|
||||
| MonkeyTypes.CustomBackgroundFilter
|
||||
)[index];
|
||||
if (arrval != arrayValue) {
|
||||
configsDifferent = true;
|
||||
console.log(`.config is different: ${arrval} != ${arrayValue}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (Config[key] != snapshot?.config?.[key]) {
|
||||
configsDifferent = true;
|
||||
console.log(
|
||||
`..config is different ${key}: ${Config[key]} != ${snapshot?.config?.[key]}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
configsDifferent = true;
|
||||
console.log(`...config is different`);
|
||||
}
|
||||
});
|
||||
if (configsDifferent) {
|
||||
console.log("configs are different, applying config from db");
|
||||
UpdateConfig.apply(snapshot.config);
|
||||
UpdateConfig.saveFullConfigToLocalStorage(true);
|
||||
}
|
||||
}
|
||||
AccountButton.loading(false);
|
||||
updateTagsCommands();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue