Limit work that happens in LiveRecipientCache lock.

This commit is contained in:
Greyson Parrelli
2025-04-23 14:03:53 -04:00
committed by Cody Henthorne
parent 7b3897cac6
commit 09b818b048

View File

@@ -113,6 +113,7 @@ public final class LiveRecipientCache {
newRecipients.stream().filter(this::isValidForCache).forEach(recipient -> {
LiveRecipient live;
boolean needsResolve;
boolean needsSet = false;
synchronized (recipients) {
live = recipients.get(recipient.getId());
@@ -122,13 +123,18 @@ public final class LiveRecipientCache {
recipients.put(recipient.getId(), live);
needsResolve = recipient.isResolving();
} else if (live.get().isResolving() || !recipient.isResolving()) {
live.set(recipient);
needsSet = true;
needsResolve = recipient.isResolving();
} else {
needsResolve = false;
}
}
// This requires taking another lock, so we move it out of the critical section above
if (needsSet) {
live.set(recipient);
}
if (needsResolve) {
LiveRecipient toResolve = live;