Reduce unneeded multiple saves for persistent marker updates

This commit is contained in:
Mike Primm 2011-11-24 01:32:10 -06:00
parent 8d11a6ffe1
commit 7d40717b1f

View file

@ -158,17 +158,24 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
private boolean stop = false; private boolean stop = false;
private Set<String> dirty_worlds = new HashSet<String>(); private Set<String> dirty_worlds = new HashSet<String>();
private boolean dirty_markers = false;
private class DoFileWrites implements Runnable { private class DoFileWrites implements Runnable {
public void run() { public void run() {
if(stop) if(stop)
return; return;
/* Write markers first - drives JSON updates too */
for(String world : dirty_worlds) { if(dirty_markers) {
writeMarkersFile(world); doSaveMarkers();
dirty_markers = false;
}
/* Process any dirty worlds */
if(!dirty_worlds.isEmpty()) {
for(String world : dirty_worlds) {
writeMarkersFile(world);
}
dirty_worlds.clear();
} }
dirty_worlds.clear();
server.getScheduler().scheduleSyncDelayedTask(dynmap, this, 20); server.getScheduler().scheduleSyncDelayedTask(dynmap, this, 20);
} }
} }
@ -237,6 +244,11 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
plugin.events.removeListener("worldactivated", api); plugin.events.removeListener("worldactivated", api);
stop = true; stop = true;
if(dirty_markers) {
doSaveMarkers();
dirty_markers = false;
}
for(MarkerIconImpl icn : markericons.values()) for(MarkerIconImpl icn : markericons.values())
icn.cleanup(); icn.cleanup();
markericons.clear(); markericons.clear();
@ -375,6 +387,11 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
* Save persistence for markers * Save persistence for markers
*/ */
static void saveMarkers() { static void saveMarkers() {
if(api != null) {
api.dirty_markers = true;
}
}
private void doSaveMarkers() {
if(api != null) { if(api != null) {
Configuration conf = new Configuration(api.markerpersist); /* Make configuration object */ Configuration conf = new Configuration(api.markerpersist); /* Make configuration object */
/* First, save icon definitions */ /* First, save icon definitions */