Skip to content

Commit

Permalink
[Fix] 추가적인 I/O를 수행하지 않도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
NARUBROWN committed May 24, 2024
1 parent 7f7beb2 commit 8d30cab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/server/inuappcenter/kr/HomepageApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
Expand All @@ -10,6 +11,7 @@
{@Server(url = "https://server.inuappcenter.kr/", description = "Default Server URL"),
@Server(url = "/", description = "Development Server URL")})
@SpringBootApplication
@EnableBatchProcessing
@EnableCaching
public class HomepageApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public class ImageService {
@Transactional(readOnly = true)
public byte[] getImage(Long id) {
return imageRedisRepository.findById(id)
.map(imageRedis -> ImageUtils.decompressImage(imageRedis.getImageData()))
.map(ImageRedis::getImageData)
.orElseGet(() -> {
Image foundImage = imageRepository.findById(id).orElseThrow(() -> new CustomNotFoundException("The requested ID was not found."));
ImageRedis imageRedis = new ImageRedis(foundImage.getId(), foundImage.getImageData());
byte[] decompressedImage = ImageUtils.decompressImage(foundImage.getImageData());
ImageRedis imageRedis = new ImageRedis(foundImage.getId(), decompressedImage);
imageRedisRepository.save(imageRedis);
return ImageUtils.decompressImage(foundImage.getImageData());
return decompressedImage;
});
}

Expand Down

0 comments on commit 8d30cab

Please sign in to comment.