mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Replace global connected plots cache with local cache
This commit is contained in:
parent
0661d0d5a1
commit
25defaac07
@ -125,9 +125,6 @@ public class Plot {
|
||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
|
||||
private static final Cleaner CLEANER = Cleaner.create();
|
||||
|
||||
static Set<Plot> connected_cache;
|
||||
static Set<CuboidRegion> regions_cache;
|
||||
|
||||
static {
|
||||
FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340);
|
||||
}
|
||||
@ -210,6 +207,8 @@ public class Plot {
|
||||
*/
|
||||
private Plot origin;
|
||||
|
||||
private Set<Plot> connectedCache;
|
||||
|
||||
/**
|
||||
* Constructor for a new plot.
|
||||
* (Only changes after plot.create() will be properly set in the database)
|
||||
@ -2131,17 +2130,16 @@ public class Plot {
|
||||
this.origin.origin = base;
|
||||
other.origin = base;
|
||||
this.origin = base;
|
||||
connected_cache = null;
|
||||
this.connectedCache = null;
|
||||
}
|
||||
} else {
|
||||
if (this.origin != null) {
|
||||
this.origin.origin = null;
|
||||
this.origin = null;
|
||||
}
|
||||
connected_cache = null;
|
||||
this.connectedCache = null;
|
||||
}
|
||||
DBFunc.setMerged(this, this.getSettings().getMerged());
|
||||
regions_cache = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2176,8 +2174,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
connected_cache = null;
|
||||
regions_cache = null;
|
||||
this.connectedCache = null;
|
||||
if (this.origin != null) {
|
||||
this.origin.origin = null;
|
||||
this.origin = null;
|
||||
@ -2327,12 +2324,11 @@ public class Plot {
|
||||
event.commit();
|
||||
return Collections.singleton(this);
|
||||
}
|
||||
if (connected_cache != null && connected_cache.contains(this)) {
|
||||
event.mergedSize = connected_cache.size();
|
||||
if (this.connectedCache != null && this.connectedCache.contains(this)) {
|
||||
event.mergedSize = this.connectedCache.size();
|
||||
event.commit();
|
||||
return connected_cache;
|
||||
return this.connectedCache;
|
||||
}
|
||||
regions_cache = null;
|
||||
|
||||
HashSet<Plot> tmpSet = new HashSet<>();
|
||||
tmpSet.add(this);
|
||||
@ -2437,7 +2433,7 @@ public class Plot {
|
||||
}
|
||||
}
|
||||
}
|
||||
connected_cache = tmpSet;
|
||||
this.connectedCache = tmpSet;
|
||||
event.mergedSize = tmpSet.size();
|
||||
event.cacheMiss = true;
|
||||
event.commit();
|
||||
@ -2452,19 +2448,15 @@ public class Plot {
|
||||
* @return all regions within the plot
|
||||
*/
|
||||
public @NonNull Set<CuboidRegion> getRegions() {
|
||||
if (regions_cache != null && connected_cache != null && connected_cache.contains(this)) {
|
||||
return regions_cache;
|
||||
}
|
||||
if (!this.isMerged()) {
|
||||
Location pos1 = this.getBottomAbs().withY(getArea().getMinBuildHeight());
|
||||
Location pos2 = this.getTopAbs().withY(getArea().getMaxBuildHeight());
|
||||
connected_cache = Sets.newHashSet(this);
|
||||
this.connectedCache = Sets.newHashSet(this);
|
||||
CuboidRegion rg = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
|
||||
regions_cache = Collections.singleton(rg);
|
||||
return regions_cache;
|
||||
return Collections.singleton(rg);
|
||||
}
|
||||
Set<Plot> plots = this.getConnectedPlots();
|
||||
Set<CuboidRegion> regions = regions_cache = new HashSet<>();
|
||||
Set<CuboidRegion> regions = new HashSet<>();
|
||||
Set<PlotId> visited = new HashSet<>();
|
||||
for (Plot current : plots) {
|
||||
if (visited.contains(current.getId())) {
|
||||
|
@ -327,6 +327,7 @@ public final class PlotModificationManager {
|
||||
ArrayList<PlotId> ids = new ArrayList<>(plots.size());
|
||||
for (Plot current : plots) {
|
||||
current.setHome(null);
|
||||
current.clearCache();
|
||||
ids.add(current.getId());
|
||||
}
|
||||
this.plot.clearRatings();
|
||||
@ -478,8 +479,7 @@ public final class PlotModificationManager {
|
||||
this.plot.updateWorldBorder();
|
||||
}
|
||||
}
|
||||
Plot.connected_cache = null;
|
||||
Plot.regions_cache = null;
|
||||
this.plot.clearCache();
|
||||
this.plot.getTrusted().clear();
|
||||
this.plot.getMembers().clear();
|
||||
this.plot.getDenied().clear();
|
||||
@ -630,6 +630,7 @@ public final class PlotModificationManager {
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
}
|
||||
visited.forEach(Plot::clearCache);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user