clear caches more aggressively in an attempt to fix rare caching issues

This commit is contained in:
Ell 2022-02-11 21:17:30 +01:00
parent bdd507885e
commit bf7760c5fb
2 changed files with 5 additions and 5 deletions

View file

@ -461,13 +461,13 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
return ret; return ret;
} }
public void clearDestinationCache(BlockPos... nodes) { public void clearDestinationCache(List<BlockPos> nodes) {
this.startProfile("clear_node_cache"); this.startProfile("clear_node_cache");
// remove caches for the nodes // remove caches for the nodes
for (var node : nodes) for (var node : nodes)
this.nodeToConnectedNodes.keySet().remove(node); this.nodeToConnectedNodes.keySet().remove(node);
// remove caches that contain the nodes as a destination // 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(); this.endProfile();
} }
@ -490,12 +490,12 @@ public class PipeNetwork implements ICapabilitySerializable<CompoundTag>, GraphL
@Override @Override
public void edgeAdded(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) { public void edgeAdded(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget()); this.clearDestinationCache(e.getEdge().pipes);
} }
@Override @Override
public void edgeRemoved(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) { public void edgeRemoved(GraphEdgeChangeEvent<BlockPos, NetworkEdge> e) {
this.clearDestinationCache(e.getEdgeSource(), e.getEdgeTarget()); this.clearDestinationCache(e.getEdge().pipes);
} }
@Override @Override

View file

@ -437,7 +437,7 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC
if (prio != pipe.priority) { if (prio != pipe.priority) {
pipe.priority = prio; pipe.priority = prio;
// clear the cache so that it's reevaluated based on priority // 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(); profiler.pop();
} }