Skip to content

Commit

Permalink
clean empty invite caches more often
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Oct 1, 2023
1 parent fb28746 commit 7a6874e
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private PartyInvites(
public void sendInvite(final UUID from, final UUID to, final UUID party) {
final Cache<UUID, UUID> cache = this.orCreateInvitesFor(to);
cache.put(from, party);
this.clean();

this.messaging.get().withPacketService(service -> {
service.queuePacket(this.packetFactory.partyInvite(from, to, party));
Expand All @@ -91,6 +92,7 @@ private void invalidateInvite_(final UUID from, final UUID to) {
if (cache != null) {
cache.invalidate(from);
}
this.clean();
}

public @Nullable Cache<UUID, UUID> invitesFor(final UUID recipient) {
Expand All @@ -107,13 +109,17 @@ private static Cache<UUID, UUID> makeCache() {

public void handle(final InvalidatePartyInvitePacket pkt) {
this.invalidateInvite_(pkt.from(), pkt.to());
this.clean();
}

private void clean() {
this.pendingInvites.values().removeIf(it -> it.asMap().size() == 0);
}

public void handle(final PartyInvitePacket pkt) {
final @Nullable Cache<UUID, UUID> cache = this.orCreateInvitesFor(pkt.to());
cache.put(pkt.from(), pkt.party());
this.pendingInvites.values().removeIf(it -> it.asMap().size() == 0);
this.clean();

final CompletableFuture<? extends CarbonPlayer> to = this.users.user(pkt.to());
final CompletableFuture<? extends CarbonPlayer> from = this.users.user(pkt.to());
Expand Down

0 comments on commit 7a6874e

Please sign in to comment.