fix: since loggedIn is determined by state we control, cache the value to avoid expensive lookups

This commit is contained in:
Johannes Frohnmeyer 2024-05-17 09:11:03 +02:00
parent d3ccb51df4
commit ac8e2f5443
Signed by: Johannes
GPG Key ID: E76429612C2929F4
2 changed files with 6 additions and 2 deletions

View File

@ -16,11 +16,13 @@ object SDCredentials {
.run { this?.userName to this?.getPasswordAsString() }
set(value) {
PasswordSafe.instance[createCredentialAttributes("httpAuth")] = Credentials(value.first, value.second)
loggedIn = value.first != null && value.second != null
}
fun logOut() {
PasswordSafe.instance[createCredentialAttributes("httpAuth")] = null
PasswordSafe.instance[createCredentialAttributes("teamId")] = null
loggedIn = false
}
var url: String
@ -34,4 +36,7 @@ object SDCredentials {
set(value) {
PasswordSafe.instance[createCredentialAttributes("teamId")] = Credentials(value)
}
var loggedIn: Boolean = credentials.first != null && credentials.second != null
private set
}

View File

@ -291,8 +291,7 @@ object SDom {
baos.toByteArray()
}))
val loggedIn: Boolean
get() = SDCredentials.credentials.first != null && SDCredentials.credentials.second != null
val loggedIn: Boolean get() = SDCredentials.loggedIn
init {
if (loggedIn) {