Moves author creation for Addressable notes to outside a @synchronized block to avoid deadlocks.

This commit is contained in:
Vitor Pamplona
2023-06-07 12:04:50 -04:00
parent 88a5e309bd
commit e9374370b9
@@ -119,19 +119,27 @@ object LocalCache {
} }
@Synchronized @Synchronized
fun getOrCreateAddressableNote(key: ATag): AddressableNote { fun getOrCreateAddressableNoteInternal(key: ATag): AddressableNote {
checkNotInMainThread() checkNotInMainThread()
// we can't use naddr here because naddr might include relay info and // we can't use naddr here because naddr might include relay info and
// the preferred relay should not be part of the index. // the preferred relay should not be part of the index.
return addressables[key.toTag()] ?: run { return addressables[key.toTag()] ?: run {
val answer = AddressableNote(key) val answer = AddressableNote(key)
answer.author = checkGetOrCreateUser(key.pubKeyHex)
addressables.put(key.toTag(), answer) addressables.put(key.toTag(), answer)
answer answer
} }
} }
fun getOrCreateAddressableNote(key: ATag): AddressableNote {
val note = getOrCreateAddressableNoteInternal(key)
// Loads the user outside a Syncronized block to avoid blocking
if (note.author == null) {
note.author = checkGetOrCreateUser(key.pubKeyHex)
}
return note
}
fun consume(event: MetadataEvent) { fun consume(event: MetadataEvent) {
// new event // new event
val oldUser = getOrCreateUser(event.pubKey) val oldUser = getOrCreateUser(event.pubKey)