Skip to content

Commit

Permalink
try to speed up the lookup without using the regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Goina committed May 30, 2024
1 parent 4b71537 commit b808a77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FileDataUtils {

private static final Map<Path, Map<String, List<String>>> FILE_NAMES_CACHE = new HashMap<>();

public static FileData lookupVariantFileData(List<String> variantLocations, Pattern variantPattern, String sourceCDMName, String variantSuffix, Function<String, String> variantSuffixMapping) {
public static FileData lookupVariantFileData(List<String> variantLocations, String fastLookup, Pattern variantPattern, String sourceCDMName, String variantSuffix, Function<String, String> variantSuffixMapping) {
if (CollectionUtils.isEmpty(variantLocations)) {
return null;
} else {
Expand All @@ -34,9 +34,9 @@ public static FileData lookupVariantFileData(List<String> variantLocations, Patt
.map(Paths::get)
.map(variantPath -> {
if (Files.isDirectory(variantPath)) {
return lookupVariantFileDataInDir(variantPath, variantPattern);
return lookupVariantFileDataInDir(variantPath, fastLookup, variantPattern);
} else if (Files.isRegularFile(variantPath)) {
return lookupVariantFileDataInArchive(variantPath, variantPattern);
return lookupVariantFileDataInArchive(variantPath, fastLookup, variantPattern);
} else {
return null;
}
Expand All @@ -47,9 +47,10 @@ public static FileData lookupVariantFileData(List<String> variantLocations, Patt
}
}

private static FileData lookupVariantFileDataInDir(Path variantPath, Pattern variantPattern) {
private static FileData lookupVariantFileDataInDir(Path variantPath, String fastLookup, Pattern variantPattern) {
Map<String, List<String>> variantDirEntries = getDirEntryNames(variantPath);
return variantDirEntries.entrySet().stream()
.filter(e -> StringUtils.contains(e.getKey(), fastLookup))
.filter(e -> {
Matcher variantMatcher = variantPattern.matcher(e.getKey());
return variantMatcher.find();
Expand All @@ -60,9 +61,10 @@ private static FileData lookupVariantFileDataInDir(Path variantPath, Pattern var
.orElse(null);
}

private static FileData lookupVariantFileDataInArchive(Path variantPath, Pattern variantPattern) {
private static FileData lookupVariantFileDataInArchive(Path variantPath, String fastLookup, Pattern variantPattern) {
Map<String, List<String>> variantArchiveEntries = getZipEntryNames(variantPath);
return variantArchiveEntries.entrySet().stream()
.filter(e -> StringUtils.contains(e.getKey(), fastLookup))
.filter(e -> {
Matcher variantMatcher = variantPattern.matcher(e.getKey());
return variantMatcher.find();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ private <N extends AbstractNeuronEntity> void populateOtherComputeFilesFromInput
ComputeFileType variantFileType = ComputeFileType.fromName(args.variantFileTypeMapping.get(variant.variantType));
FileData variantFileData = FileDataUtils.lookupVariantFileData(
Collections.singletonList(variant.variantPath),
neuronEntity.getNeuronId(),
variantPattern,
neuronEntity.getComputeFileName(ComputeFileType.SourceColorDepthImage),
variant.variantNameSuffix,
Expand Down

0 comments on commit b808a77

Please sign in to comment.