optional local mapblock saving for unittesting
parent
9079f57412
commit
7de4d370ad
|
@ -1,13 +0,0 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Maven: org.xerial:sqlite-jdbc:3.25.2">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/xerial/sqlite-jdbc/3.25.2/sqlite-jdbc-3.25.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/xerial/sqlite-jdbc/3.25.2/sqlite-jdbc-3.25.2-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/xerial/sqlite-jdbc/3.25.2/sqlite-jdbc-3.25.2-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
|
@ -3,6 +3,7 @@ package io.rudin.minetest.tileserver.accessor;
|
|||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import io.rudin.minetest.tileserver.MapBlock;
|
||||
import io.rudin.minetest.tileserver.blockdb.tables.records.BlocksRecord;
|
||||
import io.rudin.minetest.tileserver.config.TileServerConfig;
|
||||
import io.rudin.minetest.tileserver.qualifier.MapDB;
|
||||
|
@ -12,7 +13,11 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -74,9 +79,34 @@ public class BlocksRecordAccessor extends CacheLoader<Coordinate, Optional<Block
|
|||
return list;
|
||||
}
|
||||
|
||||
private File getLocalMapBlockFile(Coordinate coordinate){
|
||||
File mapblockDir = new File("mapblocks");
|
||||
if (!mapblockDir.isDirectory())
|
||||
mapblockDir.mkdir();
|
||||
|
||||
return new File(mapblockDir, coordinate.x + "." + coordinate.y + "." + coordinate.z);
|
||||
}
|
||||
|
||||
private void saveMapBlockLocally(Coordinate coordinate, BlocksRecord block){
|
||||
if (!cfg.saveMapBlocks() || block == null)
|
||||
return;
|
||||
|
||||
File file = getLocalMapBlockFile(coordinate);
|
||||
try (OutputStream output = new FileOutputStream(file)){
|
||||
output.write(block.getData());
|
||||
|
||||
} catch (Exception e){
|
||||
//debug option, nobody cares...
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void update(BlocksRecord block){
|
||||
cache.put(new Coordinate(block), Optional.of(block));
|
||||
Coordinate coordinate = new Coordinate(block);
|
||||
cache.put(coordinate, Optional.of(block));
|
||||
saveMapBlockLocally(coordinate, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,6 +128,11 @@ public class BlocksRecordAccessor extends CacheLoader<Coordinate, Optional<Block
|
|||
if (diff > 500 && cfg.logQueryPerformance()){
|
||||
logger.warn("load took {} ms", diff);
|
||||
}
|
||||
|
||||
if (record.isPresent()){
|
||||
saveMapBlockLocally(coordinate, record.get());
|
||||
}
|
||||
|
||||
return record;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,4 +188,12 @@ public interface TileServerConfig extends Config {
|
|||
@DefaultValue("false")
|
||||
boolean dumpFailedMapblocks();
|
||||
|
||||
/**
|
||||
* Saves mapblocks as local file if enabled
|
||||
* @return
|
||||
*/
|
||||
@Key("debug.mapblock.save")
|
||||
@DefaultValue("false")
|
||||
boolean saveMapBlocks();
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -8,3 +8,6 @@ tilerenderer.updateinterval=10
|
|||
minetest.db.url=jdbc:postgresql://127.0.0.1:5432/postgres
|
||||
|
||||
static.files.location=src/main/resources/public
|
||||
|
||||
# local save
|
||||
debug.mapblock.save=true
|
Loading…
Reference in New Issue