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 @@