private val logger: Logger = Logger.getLogger(IdentityLoader::class.java.name)
@Throws(WebOfTrustException::class)
- fun loadIdentities(): Map<OwnIdentity, Collection<Identity>> =
+ fun loadIdentities() =
time({ stopwatch, identities -> "Loaded ${identities.size} own identities in ${stopwatch.elapsed(MILLISECONDS) / 1000.0}s." }) {
webOfTrustConnector.loadAllOwnIdentities()
}.let(this::loadTrustedIdentitiesForOwnIdentities)
@Throws(PluginException::class)
private fun loadTrustedIdentitiesForOwnIdentities(ownIdentities: Collection<OwnIdentity>) =
- ownIdentities.associateWith { ownIdentity ->
- if (ownIdentity.doesNotHaveCorrectContext()) {
- emptySet<Identity>()
- } else {
- time({ stopwatch, identities -> "Loaded ${identities.size} identities for ${ownIdentity.nickname} in ${stopwatch.elapsed(MILLISECONDS) / 1000.0}s." }) {
- webOfTrustConnector.loadTrustedIdentities(ownIdentity, context?.context)
+ ownIdentities
+ .also { logger.fine { "Getting trusted identities for ${it.size} own identities..." } }
+ .associateWith { ownIdentity ->
+ logger.fine { "Getting trusted identities for $ownIdentity..." }
+ if (ownIdentity.doesNotHaveCorrectContext()) {
+ logger.fine { "Skipping $ownIdentity because of incorrect context." }
+ emptySet()
+ } else {
+ logger.fine { "Loading trusted identities for $ownIdentity from WoT..." }
+ time({ stopwatch, identities -> "Loaded ${identities.size} identities for ${ownIdentity.nickname} in ${stopwatch.elapsed(MILLISECONDS) / 1000.0}s." }) {
+ webOfTrustConnector.loadTrustedIdentities(ownIdentity, context?.context)
+ }
+ }
}
- }
- }
private fun OwnIdentity.doesNotHaveCorrectContext() =
- context != null && !hasContext(context.context)
+ context?.let { it.context !in contexts } ?: false
- private fun <R> time(logMessage: (Stopwatch, Collection<R>) -> String, loader: () -> Collection<R>): Collection<R> =
+ private fun <R> time(logMessage: (Stopwatch, R) -> String, loader: () -> R) =
Stopwatch.createStarted().let { stopwatch ->
loader().also { logger.fine(logMessage(stopwatch, it)) }
}