From 92f9601a9cdc653391b583a6fc2ed4fa63ff3f3b Mon Sep 17 00:00:00 2001 From: MiniDay <372403923@qq.com> Date: Sun, 9 Apr 2023 22:45:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=80=E5=8F=91=E4=B8=AD...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../blog/service/impl/AttachService.java | 17 +++++++++-- .../manage/AttachManageComponent.vue | 29 ++++++++++--------- .../swagger/models/blog-update-require-vo.ts | 2 +- blog-frontend/src/views/BlogEditView.vue | 1 - 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/blog-backend/src/main/java/cn/hamster3/application/blog/service/impl/AttachService.java b/blog-backend/src/main/java/cn/hamster3/application/blog/service/impl/AttachService.java index 82242f9..16ec78e 100644 --- a/blog-backend/src/main/java/cn/hamster3/application/blog/service/impl/AttachService.java +++ b/blog-backend/src/main/java/cn/hamster3/application/blog/service/impl/AttachService.java @@ -48,15 +48,21 @@ public class AttachService implements IAttachService { if (checked != null) { return checked; } - log.info("prepare to save file: {}({} bytes)", file.getOriginalFilename(), file.getSize()); + log.info("prepare to save file: {}({} kb)", file.getOriginalFilename(), file.getSize() / 1024.0); + long time1 = System.currentTimeMillis(); AttachEntity attachEntity = new AttachEntity(); attachEntity.setFilename(file.getOriginalFilename()); attachEntity.setContentType(file.getContentType()); attachEntity.setData(file.getBytes()); attachEntity = attachRepo.save(attachEntity); + long time2 = System.currentTimeMillis(); + log.info("file upload finished, took {} ms", time2 - time1); File localCacheFile = new File(ATTACH_FOLDER, String.valueOf(attachEntity.getId())); Files.copy(file.getInputStream(), localCacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + log.info("written attach data to local cache file: {}. took {} ms", + localCacheFile.getName(), + System.currentTimeMillis() - time2); return ResponseVO.success(attachEntity.getId()); } @@ -113,16 +119,23 @@ public class AttachService implements IAttachService { if (!attachRepo.existsById(attachID)) { return ResponseVO.notFound(); } + log.info("update attach {}, save file {} to database. ({} kb)", attachID, + file.getOriginalFilename(), file.getSize() / 1024.0); + long time1 = System.currentTimeMillis(); attachRepo.updateFilenameAndContentTypeAndDataById( file.getOriginalFilename(), file.getContentType(), file.getBytes(), attachID ); + long time2 = System.currentTimeMillis(); + log.info("file upload finished, took {} ms", time2 - time1); File localCacheFile = new File(ATTACH_FOLDER, String.valueOf(attachID)); Files.copy(file.getInputStream(), localCacheFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - log.info("written attach data to local cache file: {}", localCacheFile.getName()); + log.info("written attach data to local cache file: {}. took {} ms", + localCacheFile.getName(), + System.currentTimeMillis() - time2); return ResponseVO.success(); } diff --git a/blog-frontend/src/components/manage/AttachManageComponent.vue b/blog-frontend/src/components/manage/AttachManageComponent.vue index 41ad8b1..2e67de7 100644 --- a/blog-frontend/src/components/manage/AttachManageComponent.vue +++ b/blog-frontend/src/components/manage/AttachManageComponent.vue @@ -1,7 +1,7 @@