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:
Gina Häußge 2017-06-30 14:36:18 +02:00
parent 96ee80afd2
commit e309646504
3 changed files with 21 additions and 2 deletions

View file

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

View file

@ -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) {

View file

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