fix: don't clear cache prematurely when there are multiple pack managers
ci/woodpecker/push/docs Pipeline was successful Details
ci/woodpecker/push/jfmod Pipeline was successful Details
ci/woodpecker/tag/docs Pipeline was successful Details
ci/woodpecker/tag/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2024-05-05 15:43:23 +02:00
parent 403a595a74
commit 08a205f828
Signed by: Johannes
GPG Key ID: E76429612C2929F4
3 changed files with 10 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import io.gitlab.jfronny.respackopts.RespackoptsConfig;
import io.gitlab.jfronny.respackopts.model.DiscoveredPack;
import io.gitlab.jfronny.respackopts.model.GC_PackMeta;
import io.gitlab.jfronny.respackopts.model.PackMeta;
import io.gitlab.jfronny.respackopts.model.cache.CacheKey;
import io.gitlab.jfronny.respackopts.util.FallbackI18n;
import io.gitlab.jfronny.respackopts.util.MetaCache;
import net.minecraft.resource.*;
@ -23,13 +24,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
@Mixin(ResourcePackManager.class)
public class ResourcePackManagerMixin {
@Shadow private Map<String, ResourcePackProfile> profiles;
@Unique private final Set<CacheKey> rpo$cache = new HashSet<>(); // Tracked here since there might be multiple pack managers (e.g. resource and data)
@Inject(at = @At("TAIL"), method = "scanPacks()V")
private void scanPacks(CallbackInfo info) {
@ -41,7 +41,9 @@ public class ResourcePackManagerMixin {
if (dp != null) discoveredPacks.add(dp);
}
});
MetaCache.addFromScan(discoveredPacks);
Set<CacheKey> newKeys = MetaCache.addFromScan(discoveredPacks, rpo$cache);
rpo$cache.clear();
rpo$cache.addAll(newKeys);
RespackoptsConfig.scanState = RespackoptsConfig.ScanState.DONE;
}

View File

@ -28,7 +28,7 @@ public record CachedPackState(
Map<String, String> cachedFiles, // Files, read by readString
Scope executionScope,
@Nullable FileDependencyTracker tracker
) {
) {
public CachedPackState(CacheKey key, PackMeta meta, ConfigBranch branch) {
this(
meta.id,

View File

@ -57,7 +57,7 @@ public class MetaCache {
}
}
public static void addFromScan(List<DiscoveredPack> discoveredPacks) {
public static Set<CacheKey> addFromScan(List<DiscoveredPack> discoveredPacks, Set<CacheKey> previousKeys) {
FallbackI18n.clear();
Set<CacheKey> newKeys = new HashSet<>();
Set<String> ids = new HashSet<>();
@ -68,8 +68,9 @@ public class MetaCache {
Respackopts.LOGGER.warn("Duplicate pack id: {0}", pack.meta().id);
}
}
PACK_STATES.keySet().stream().filter(s -> !newKeys.contains(s)).toList().forEach(MetaCache::remove);
previousKeys.stream().filter(s -> !newKeys.contains(s)).forEach(MetaCache::remove);
save(SaveHook.Arguments.DO_NOTHING);
return newKeys;
}
public static CacheKey addFromScan(String displayName, String packName, PackMeta meta, Path dataLocation) {