服务启动时减少io操作

This commit is contained in:
lzy
2023-10-25 18:07:01 +08:00
parent 0994138d10
commit ec75800781
4 changed files with 50 additions and 8 deletions

View File

@ -11,6 +11,7 @@ import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter;
import ai.chat2db.server.web.api.controller.rdb.doc.DatabaseExportService;
import ai.chat2db.server.web.api.controller.rdb.doc.conf.ExportOptions;
import ai.chat2db.server.web.api.controller.rdb.doc.event.TemplateEvent;
import ai.chat2db.server.web.api.controller.rdb.factory.ExportServiceFactory;
import ai.chat2db.server.web.api.controller.rdb.request.DataExportRequest;
import ai.chat2db.server.web.api.controller.rdb.vo.TableVO;
@ -20,6 +21,7 @@ import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -48,6 +50,9 @@ public class RdbDocController {
@Autowired
private RdbWebConverter rdbWebConverter;
@Autowired
private ApplicationContext applicationContext;
/**
* export data
*
@ -55,6 +60,8 @@ public class RdbDocController {
*/
@PostMapping("/export")
public void export(@Valid @RequestBody DataExportRequest request, HttpServletResponse response) throws Exception {
//复制模板
applicationContext.publishEvent(new TemplateEvent("copy"));
ExportTypeEnum exportType = EasyEnumUtils.getEnum(ExportTypeEnum.class, request.getExportType());
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode(

View File

@ -0,0 +1,14 @@
package ai.chat2db.server.web.api.controller.rdb.doc.event;
import org.springframework.context.ApplicationEvent;
/**
* TemplateEvent
*
* @author lzy
**/
public class TemplateEvent extends ApplicationEvent {
public TemplateEvent(String key) {
super(key);
}
}