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