From bf7760c5fb3e2957064cd07d756226c47bf38193 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 11 Feb 2022 21:17:30 +0100 Subject: [PATCH] clear caches more aggressively in an attempt to fix rare caching issues --- .../java/de/ellpeck/prettypipes/network/PipeNetwork.java | 8 ++++---- .../java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java index a98d10e..df767ad 100644 --- a/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java +++ b/src/main/java/de/ellpeck/prettypipes/network/PipeNetwork.java @@ -461,13 +461,13 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL return ret; } - public void clearDestinationCache(BlockPos... nodes) { + public void clearDestinationCache(List nodes) { this.startProfile("clear_node_cache"); // remove caches for the nodes for (var node : nodes) this.nodeToConnectedNodes.keySet().remove(node); // remove caches that contain the nodes as a destination - this.nodeToConnectedNodes.values().removeIf(cached -> Arrays.stream(nodes).anyMatch(cached::contains)); + this.nodeToConnectedNodes.values().removeIf(cached -> nodes.stream().anyMatch(cached::contains)); this.endProfile(); } @@ -490,12 +490,12 @@ public class PipeNetwork implements ICapabilitySerializable, GraphL @Override public void edgeAdded(GraphEdgeChangeEvent e) { - this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget()); + this.clearDestinationCache(e.getEdge().pipes); } @Override public void edgeRemoved(GraphEdgeChangeEvent e) { - this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget()); + this.clearDestinationCache(e.getEdge().pipes); } @Override diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java index 7d29092..acb78a7 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java @@ -437,7 +437,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC if (prio != pipe.priority) { pipe.priority = prio; // clear the cache so that it's reevaluated based on priority - PipeNetwork.get(pipe.level).clearDestinationCache(pipe.worldPosition); + PipeNetwork.get(pipe.level).clearDestinationCache(Collections.singletonList(pipe.worldPosition)); } profiler.pop(); }