Commit cc6040ed authored by Piotr Gawron's avatar Piotr Gawron
Browse files

prevent to load logged user data twice

parent 0d41836f
Pipeline #4370 passed with stage
in 1 minute and 24 seconds
......@@ -971,7 +971,7 @@ ServerConnector.getLoggedUser = function () {
if (self._loggedUser !== undefined) {
return Promise.resolve(self._loggedUser);
} else {
return self.getUser(self.getSessionData().getLogin()).then(function (user) {
self._loggedUser = self.getUser(self.getSessionData().getLogin()).then(function (user) {
if (user !== null) {
self._loggedUser = user;
return self._loggedUser;
......@@ -979,6 +979,7 @@ ServerConnector.getLoggedUser = function () {
return Promise.reject(new Error("User " + self.getSessionData().getLogin() + " doesn't exist"));
}
});
return self._loggedUser;
}
};
......
......@@ -402,5 +402,22 @@ describe('ServerConnector', function () {
});
});
it('getLoggedUser called twice', function () {
var called = 0;
var orginalFunction = ServerConnector.getUser;
ServerConnector.getUser = function (login) {
called++;
return Promise.delay(20, orginalFunction.call(ServerConnector, login));
};
var promises = [ServerConnector.getLoggedUser(), ServerConnector.getLoggedUser()];
return Promise.all(promises).then(function (result) {
assert.ok(result[0] === result[1]);
assert.equal(1, called);
}).finally(function () {
ServerConnector.getUser = orginalFunction;
});
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment