9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-19 15:09:18 +00:00

stop writing first access each time the engine is opened

This commit is contained in:
Julian Krings
2025-10-30 16:40:35 +01:00
parent be35e49302
commit ea5919def2

View File

@@ -46,6 +46,7 @@ import lombok.ToString;
import java.io.*; import java.io.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -170,7 +171,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
return possibleKeys; return possibleKeys;
} }
KSet<String> m = new KSet<>();
KList<File> files = getFolders(); KList<File> files = getFolders();
if (files == null) { if (files == null) {
@@ -178,6 +178,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
return possibleKeys; return possibleKeys;
} }
HashSet<String> m = new HashSet<>();
for (File i : files) { for (File i : files) {
for (File j : matchAllFiles(i, (f) -> f.getName().endsWith(".json"))) { for (File j : matchAllFiles(i, (f) -> f.getName().endsWith(".json"))) {
m.add(i.toURI().relativize(j.toURI()).getPath().replaceAll("\\Q.json\\E", "")); m.add(i.toURI().relativize(j.toURI()).getPath().replaceAll("\\Q.json\\E", ""));
@@ -319,7 +320,8 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
return null; return null;
} }
firstAccess.add(name); var set = firstAccess;
if (set != null) firstAccess.add(name);
return loadCache.get(name); return loadCache.get(name);
} }
@@ -342,21 +344,24 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
} }
din.close(); din.close();
file.deleteOnExit();
Iris.info("Loading " + s.size() + " prefetch " + getFolderName()); Iris.info("Loading " + s.size() + " prefetch " + getFolderName());
firstAccess = null;
loadAllParallel(s); loadAllParallel(s);
} }
public void saveFirstAccess(Engine engine) throws IOException { public void saveFirstAccess(Engine engine) throws IOException {
if (firstAccess == null) return;
String id = "DIM" + Math.abs(engine.getSeedManager().getSeed() + engine.getDimension().getVersion() + engine.getDimension().getLoadKey().hashCode()); String id = "DIM" + Math.abs(engine.getSeedManager().getSeed() + engine.getDimension().getVersion() + engine.getDimension().getLoadKey().hashCode());
File file = Iris.instance.getDataFile("prefetch/" + id + "/" + Math.abs(getFolderName().hashCode()) + ".ipfch"); File file = Iris.instance.getDataFile("prefetch/" + id + "/" + Math.abs(getFolderName().hashCode()) + ".ipfch");
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
GZIPOutputStream gzo = new CustomOutputStream(fos, 9); GZIPOutputStream gzo = new CustomOutputStream(fos, 9);
DataOutputStream dos = new DataOutputStream(gzo); DataOutputStream dos = new DataOutputStream(gzo);
dos.writeInt(firstAccess.size()); var set = firstAccess;
firstAccess = null;
dos.writeInt(set.size());
for (String i : firstAccess) { for (String i : set) {
dos.writeUTF(i); dos.writeUTF(i);
} }