Skip to content

Commit

Permalink
refactor : N+1 쿼리를 찾는 Template의 메서드명을 직관적으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
joon6093 committed Sep 24, 2024
1 parent b6710e1 commit ae4aa86
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public ConnectionProxyAspect(final NPlusOneQueryTemplate nPlusOneQueryTemplate)
@Around("execution(* javax.sql.DataSource.getConnection())")
public Object wrapConnectionWithProxy(final ProceedingJoinPoint joinPoint) throws Throwable {
final Connection originalConnection = (Connection) joinPoint.proceed();
return ConnectionProxyFactory.createProxy(originalConnection, nPlusOneQueryTemplate::handleNPlusOneIssues);
return ConnectionProxyFactory.createProxy(originalConnection, nPlusOneQueryTemplate::handleQueryContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public NPlusOneQueryCollector(final int queryThreshold, final ExceptionContext e
}

@Override
protected void handleDetectedNPlusOneIssue(final String query, final Long count) {
protected void handleDetectedNPlusOneQuery(final String query, final Long count) {
exceptionContext.saveException(new NPlusOneQueryException(query, count));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public NPlusOneQueryLogger(final int queryThreshold, final Level level) {
}

@Override
protected void handleDetectedNPlusOneIssue(final String query, final Long count) {
protected void handleDetectedNPlusOneQuery(final String query, final Long count) {
if (level == Level.WARN && logger.isWarnEnabled()) {
logger.warn("N+1 issue detected: '{}' was executed {} times.", query, count);
} else if (level == Level.TRACE && logger.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ public NPlusOneQueryTemplate(final int queryThreshold) {
this.queryThreshold = queryThreshold;
}

public final void handleNPlusOneIssues() {
public final void handleQueryContext() {
try {
QueryContextHolder.getContext().getQueryCounts().forEach((query, count) -> {
if (count >= queryThreshold) {
handleDetectedNPlusOneIssue(query, count);
handleDetectedNPlusOneQuery(query, count);
}
});
} finally {
QueryContextHolder.clearContext();
}
}

protected abstract void handleDetectedNPlusOneIssue(final String query, final Long count);
protected abstract void handleDetectedNPlusOneQuery(final String query, final Long count);
}

0 comments on commit ae4aa86

Please sign in to comment.