Prevent unnecessary settings fetch during startup
We fetch settings once explicitly after passive login but before completed startup. Without this patch we fetched them again after onUserLoggedIn got fired (if it got fired by the passive login) during startup. That's not necessary because we did the passive login before our initial settings fetch, so IF that already logged us in, our settings fetch already was done with us logged in as well and the onUserLoggedIn later only tells us what we already knew.
This commit is contained in:
parent
96ee80afd2
commit
e309646504
3 changed files with 21 additions and 2 deletions
|
|
@ -983,6 +983,22 @@ function getOnlyChangedData(data, oldData) {
|
|||
return f(data, oldData);
|
||||
}
|
||||
|
||||
function setOnViewModels(allViewModels, key, value) {
|
||||
setOnViewModelsIf(allViewModels, key, value, undefined);
|
||||
}
|
||||
|
||||
function setOnViewModelsIf(allViewModels, key, value, condition) {
|
||||
if (condition === undefined || !_.isFunction(condition)) {
|
||||
condition = function() { return true; };
|
||||
}
|
||||
|
||||
_.each(allViewModels, function(viewModel) {
|
||||
if (condition(viewModel)) {
|
||||
viewModel[key] = value;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function callViewModels(allViewModels, method, callback) {
|
||||
callViewModelsIf(allViewModels, method, undefined, callback);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -613,6 +613,7 @@ $(function() {
|
|||
|
||||
// startup complete
|
||||
callViewModels(allViewModels, "onStartupComplete");
|
||||
setOnViewModels(allViewModels, "_startupComplete", true);
|
||||
|
||||
// make sure we can track the browser tab visibility
|
||||
OctoPrint.coreui.onBrowserVisibilityChange(function(status) {
|
||||
|
|
|
|||
|
|
@ -884,12 +884,14 @@ $(function() {
|
|||
};
|
||||
|
||||
self.onUserLoggedIn = function() {
|
||||
// we might have other user rights now, refresh
|
||||
// we might have other user rights now, refresh (but only if startup has fully completed)
|
||||
if (!self._startupComplete) return;
|
||||
self.requestData();
|
||||
};
|
||||
|
||||
self.onUserLoggedOut = function() {
|
||||
// we might have other user rights now, refresh
|
||||
// we might have other user rights now, refresh (but only if startup has fully completed)
|
||||
if (!self._startupComplete) return;
|
||||
self.requestData();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue