fix(测试跟踪): 同步缺陷附件时,内存占用过大,导致OOM
--bug=1024770 --user=陈建星 [测试跟踪]同步JIRA缺陷失败,页面一致转圈后服务挂了 https://www.tapd.cn/55049933/s/1356110
This commit is contained in:
parent
a53347707a
commit
8c0f963d72
2
pom.xml
2
pom.xml
|
@ -22,7 +22,7 @@
|
|||
<java.version>17</java.version>
|
||||
<spring-cloud.version>2022.0.1</spring-cloud.version>
|
||||
<dubbo.version>2.7.18</dubbo.version>
|
||||
<platform-plugin-sdk.version>1.4.0</platform-plugin-sdk.version>
|
||||
<platform-plugin-sdk.version>1.5.0</platform-plugin-sdk.version>
|
||||
<shiro.version>1.11.0</shiro.version>
|
||||
<java-websocket.version>1.5.3</java-websocket.version>
|
||||
<easyexcel.version>3.1.1</easyexcel.version>
|
||||
|
|
|
@ -468,17 +468,18 @@ public class AttachmentService {
|
|||
return fileAttachmentMetadata;
|
||||
}
|
||||
|
||||
public FileAttachmentMetadata saveAttachmentByBytes(byte[] bytes, String attachmentType, String belongId, String attachmentName) {
|
||||
public FileAttachmentMetadata saveAttachmentByBytes(InputStream in, String attachmentType, String belongId, String attachmentName) {
|
||||
String uploadPath = FileUtils.ATTACHMENT_DIR + "/" + attachmentType + "/" + belongId;
|
||||
File parentFile = new File(uploadPath);
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
try (OutputStream os = new FileOutputStream(uploadPath + "/" + attachmentName)) {
|
||||
InputStream in = new ByteArrayInputStream(bytes);
|
||||
int len = 0;
|
||||
int total = 0;
|
||||
int len;
|
||||
byte[] buf = new byte[1024];
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
total += len;
|
||||
os.write(buf, 0, len);
|
||||
}
|
||||
os.flush();
|
||||
|
@ -487,7 +488,7 @@ public class AttachmentService {
|
|||
fileAttachmentMetadata.setId(UUID.randomUUID().toString());
|
||||
fileAttachmentMetadata.setName(attachmentName);
|
||||
fileAttachmentMetadata.setType(getFileTypeWithoutEnum(attachmentName));
|
||||
fileAttachmentMetadata.setSize(Integer.valueOf(bytes.length).longValue());
|
||||
fileAttachmentMetadata.setSize(Integer.valueOf(total).longValue());
|
||||
fileAttachmentMetadata.setCreateTime(System.currentTimeMillis());
|
||||
fileAttachmentMetadata.setUpdateTime(System.currentTimeMillis());
|
||||
fileAttachmentMetadata.setCreator(SessionUtils.getUser().getName());
|
||||
|
|
|
@ -1135,17 +1135,19 @@ public class IssuesService {
|
|||
String fileName, String fileKey,
|
||||
AttachmentModuleRelationMapper batchAttachmentModuleRelationMapper) {
|
||||
try {
|
||||
byte[] content = platform.getAttachmentContent(fileKey);
|
||||
if (content == null) {
|
||||
platform.getAttachmentContent(fileKey, (in) -> {
|
||||
if (in == null) {
|
||||
return;
|
||||
}
|
||||
FileAttachmentMetadata fileAttachmentMetadata = attachmentService
|
||||
.saveAttachmentByBytes(content, AttachmentType.ISSUE.type(), issueId, fileName);
|
||||
.saveAttachmentByBytes(in, AttachmentType.ISSUE.type(), issueId, fileName);
|
||||
AttachmentModuleRelation attachmentModuleRelation = new AttachmentModuleRelation();
|
||||
attachmentModuleRelation.setAttachmentId(fileAttachmentMetadata.getId());
|
||||
attachmentModuleRelation.setRelationId(issueId);
|
||||
attachmentModuleRelation.setRelationType(AttachmentType.ISSUE.type());
|
||||
batchAttachmentModuleRelationMapper.insert(attachmentModuleRelation);
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue