批量删除文件性能优化
This commit is contained in:
parent
ba5e891098
commit
450d87bbc8
@ -3,6 +3,9 @@ package com.qiwenshare.file;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
|
||||
import org.springframework.boot.web.server.ErrorPage;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
@ -10,6 +13,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@ -22,5 +26,11 @@ public class FileApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(FileApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
|
||||
return factory -> {
|
||||
ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/");
|
||||
factory.addErrorPages(error404Page);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ public class FileDealComp {
|
||||
UserFileMapper userFileMapper;
|
||||
@Autowired
|
||||
private IElasticSearchService elasticSearchService;
|
||||
public static Executor exec = Executors.newFixedThreadPool(10);
|
||||
|
||||
@Resource
|
||||
UFOFactory ufoFactory;
|
||||
@ -228,6 +229,7 @@ public class FileDealComp {
|
||||
|
||||
|
||||
public void uploadESByUserFileId(Long userFileId) {
|
||||
exec.execute(()->{
|
||||
try {
|
||||
UserFile userFile = new UserFile();
|
||||
userFile.setUserFileId(userFileId);
|
||||
@ -235,30 +237,35 @@ public class FileDealComp {
|
||||
if (userfileResult != null && userfileResult.size() > 0) {
|
||||
FileSearch fileSearch = new FileSearch();
|
||||
BeanUtil.copyProperties(userfileResult.get(0), fileSearch);
|
||||
if (fileSearch.getIsDir() == 0) {
|
||||
|
||||
Reader reader = ufoFactory.getReader(fileSearch.getStorageType());
|
||||
ReadFile readFile = new ReadFile();
|
||||
readFile.setFileUrl(fileSearch.getFileUrl());
|
||||
String content = reader.read(readFile);
|
||||
//全文搜索
|
||||
// fileSearch.setContent(content);
|
||||
|
||||
}
|
||||
// if (fileSearch.getIsDir() == 0) {
|
||||
//
|
||||
// Reader reader = ufoFactory.getReader(fileSearch.getStorageType());
|
||||
// ReadFile readFile = new ReadFile();
|
||||
// readFile.setFileUrl(fileSearch.getFileUrl());
|
||||
// String content = reader.read(readFile);
|
||||
// //全文搜索
|
||||
// // fileSearch.setContent(content);
|
||||
//
|
||||
// }
|
||||
elasticSearchService.save(fileSearch);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("ES更新操作失败,请检查配置");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void deleteESByUserFileId(Long userFileId) {
|
||||
exec.execute(()->{
|
||||
try {
|
||||
elasticSearchService.deleteById(userFileId);
|
||||
} catch (Exception e) {
|
||||
log.error("ES删除操作失败,请检查配置");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +173,7 @@ public class FiletransferController {
|
||||
httpServletResponse.addHeader("Content-Disposition", "fileName=" + fileName);// 设置文件名
|
||||
DownloadFileDTO downloadFileDTO = new DownloadFileDTO();
|
||||
downloadFileDTO.setUserFileId(previewDTO.getUserFileId());
|
||||
downloadFileDTO.setIsMin(previewDTO.getIsMin());
|
||||
try {
|
||||
filetransferService.downloadFile(httpServletResponse, downloadFileDTO);
|
||||
}catch (Exception e){
|
||||
|
@ -7,5 +7,5 @@ import lombok.Data;
|
||||
@Schema(name = "下载文件DTO",required = true)
|
||||
public class DownloadFileDTO {
|
||||
private Long userFileId;
|
||||
private boolean isMin;
|
||||
private String isMin;
|
||||
}
|
||||
|
@ -8,4 +8,5 @@ import lombok.Data;
|
||||
public class PreviewDTO {
|
||||
private Long userFileId;
|
||||
private String token;
|
||||
private String isMin;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class FiletransferService implements IFiletransferService {
|
||||
throw new UploadException("下载失败");
|
||||
}
|
||||
DownloadFile downloadFile = new DownloadFile();
|
||||
if (downloadFileDTO.isMin()) {
|
||||
if ("true".equals(downloadFileDTO.getIsMin())) {
|
||||
downloadFile.setFileUrl(fileBean.getFileUrl().replace("." + userFile.getExtendName(), "_min." + userFile.getExtendName()));
|
||||
} else {
|
||||
downloadFile.setFileUrl(fileBean.getFileUrl());
|
||||
|
Loading…
Reference in New Issue
Block a user