perf[storage]: use another collection to store resources

This commit is contained in:
godotg
2022-12-13 11:27:15 +08:00
parent d95088cfa8
commit bcae705849
2 changed files with 5 additions and 4 deletions
@@ -258,20 +258,22 @@ public class StorageManager implements IStorageManager {
var resourceSet = new HashSet<Resource>();
var resourceLocations = StringUtils.tokenize(storageConfig.getResourceLocation(), ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
for (var resourceLocation : resourceLocations) {
var resources = new ArrayList<Resource>();
var packageSearchPath = StringUtils.format("{}/**/{}.*", resourceLocation, clazz.getSimpleName());
packageSearchPath = packageSearchPath.replaceAll("//", "/");
try {
Arrays.stream(resourcePatternResolver.getResources(packageSearchPath)).filter(it -> ResourceEnum.containsResourceEnum(FileUtils.fileExtName(it.getFilename()))).forEach(it -> resourceSet.add(it));
Arrays.stream(resourcePatternResolver.getResources(packageSearchPath)).filter(it -> ResourceEnum.containsResourceEnum(FileUtils.fileExtName(it.getFilename()))).forEach(it -> resources.add(it));
} catch (Exception e) {
// do nothing
}
// 通配符无法匹配根目录,所以如果找不到,再从根目录查找一遍
if (resourceSet.isEmpty()) {
if (resources.isEmpty()) {
packageSearchPath = StringUtils.format("{}/{}.*", resourceLocation, clazz.getSimpleName());
packageSearchPath = packageSearchPath.replaceAll("//", "/");
Arrays.stream(resourcePatternResolver.getResources(packageSearchPath)).filter(it -> ResourceEnum.containsResourceEnum(FileUtils.fileExtName(it.getFilename()))).forEach(it -> resourceSet.add(it));
Arrays.stream(resourcePatternResolver.getResources(packageSearchPath)).filter(it -> ResourceEnum.containsResourceEnum(FileUtils.fileExtName(it.getFilename()))).forEach(it -> resources.add(it));
}
resourceSet.addAll(resources);
}
if (CollectionUtils.isEmpty(resourceSet)) {
@@ -50,7 +50,6 @@ public class ApplicationTest {
var studentResources = studentManager.studentResources;
var studentCsvResources = studentManager.studentCsvResources;
// 类名称和Excel名称必须完全一致,Excel的列名称必须对应对象的属性名称
// 类名称和Excel名称必须完全一致,Excel的列名称必须对应对象的属性名称
for (StudentResource resource : studentResources.getAll()) {
logger.info(JsonUtils.object2String(resource));
}