Skip to content

Commit

Permalink
Merge pull request #314 from HyunJunSon/tuning/api
Browse files Browse the repository at this point in the history
Refactor:: api 성능개선,
  • Loading branch information
HyunJunSon authored Mar 21, 2024
2 parents 1b92d45 + 02fba23 commit 6fd1f80
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

@EnableCaching
@SpringBootApplication
public class ModuleApiApplication {

Expand Down
12 changes: 6 additions & 6 deletions module-api/src/main/java/com/kernel360/global/aop/LogAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class LogAspect {

@Around("@annotation(com.kernel360.global.annotation.LogExecutionTime)")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
long start = System.nanoTime();
Object proceed = joinPoint.proceed();

long executionTime = System.currentTimeMillis() - start;
log.info("##### @LogExecutionTime ##### " + joinPoint.getSignature() + " executed in " + executionTime + "ms");
long executionTime = System.nanoTime() - start;
log.info("##### @LogExecutionTime ##### " + joinPoint.getSignature() + " executed in " + executionTime + "ns");

return proceed;
}
Expand All @@ -29,13 +29,13 @@ public void controller() {}

@Around("controller()")
public Object logApiExecTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
long start = System.nanoTime();
Object proceed = joinPoint.proceed();

long executionTime = System.currentTimeMillis() - start;
long executionTime = System.nanoTime() - start;
Signature signature = joinPoint.getSignature();

log.info(String.format("##### @API Execution Time ##### [%dms] → %s.%s",
log.info(String.format("##### @API Execution Time ##### [%dns] → %s.%s",
executionTime, signature.getDeclaringTypeName(), signature.getName()));

return proceed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
@Slf4j
@Component
public class LogFilter implements Filter {
private static final Trie<String, Integer> DENIED_LIST = new PatriciaTrie<>();

static {
DENIED_LIST.put("/actuator/prometheus", 0);
}

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
Expand Down Expand Up @@ -61,16 +66,9 @@ private static void printLog(FilterChain chain, ContentCachingRequestWrapper req
});

String responseBody = new String(response.getContentAsByteArray());
if(!deninedList().containsKey(uri) && !uri.startsWith("/docs/")) {
if(!DENIED_LIST.containsKey(uri) && !uri.startsWith("/docs/")) {
log.info("##### RESPONSE ##### uri: {}, method: {}, header: {}, body: {}", uri, method, responseHeaderValues, responseBody);
}
response.copyBodyToResponse();
}

private static Trie<String, Integer> deninedList(){
Trie<String, Integer> trie = new PatriciaTrie<>();

trie.put("/actuator/prometheus",0);
return trie;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.kernel360.product.entity.Product;
import com.kernel360.product.enumset.SafetyStatus;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
* DTO for {@link com.kernel360.product.entity.Product}
*/
public record ProductDto(
public record ProductDto (
Long productNo,
String productName,
String barcode,
Expand All @@ -21,7 +23,7 @@ public record ProductDto(
String createdBy,
LocalDateTime modifiedAt,
String modifiedBy
) {
) implements Serializable{

public static ProductDto of(
Long productNo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.kernel360.product.enumset.SafetyStatus;
import com.kernel360.product.repository.ProductRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
Expand All @@ -27,6 +28,7 @@ public class ProductService {
private final ProductRepository productRepository;
private final LikeRepository likeRepository;

@Cacheable(value = "productsCache")
@Transactional(readOnly = true)
public List<ProductDto> getProducts() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;


@Getter
@Entity
@Table(name = "product")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Product extends BaseEntity {

Expand Down

0 comments on commit 6fd1f80

Please sign in to comment.