-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(P6spy): 정책에 따른 P6Spy 관련 설정 수정 * refactor(DB): SRID 수정 - SRID 를 0에서 5179로 변경 - 공간 인덱스를 설정하기 위함 * refactor(DB): 공간 인덱스 및 세컨더리 인덱스 추가 - 공간 인덱스 적용으로 성능 1만개 데이터 기준 6배 향상 - 유저 세컨더리 인덱스 적용으로 성능 1만개 기준 3배 향상 * feat: GeometryUtils 추가 - 동일한 SRID를 적용하기 위해 * feat: SRID 변경 코드 적용 및 인덱스 쿼리 추가 * feat: 데이터 제너레이터 및 로더 추가 - 데이터를 손쉽게 추가하기 위함 * fix: 유니크 제약으로 인한 테스트 수정 * fix: 유니크 제약으로 인한 테스트 수정
- Loading branch information
1 parent
75b474b
commit 2624754
Showing
28 changed files
with
607 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 2 additions & 46 deletions
48
src/main/java/com/prgrms/mukvengers/global/config/p6spy/P6spyConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,16 @@ | ||
package com.prgrms.mukvengers.global.config.p6spy; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import org.hibernate.engine.jdbc.internal.FormatStyle; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.p6spy.engine.logging.Category; | ||
import com.p6spy.engine.spy.P6SpyOptions; | ||
import com.p6spy.engine.spy.appender.MessageFormattingStrategy; | ||
|
||
@Configuration | ||
public class P6spyConfig implements MessageFormattingStrategy { | ||
public class P6spyConfig { | ||
|
||
@PostConstruct | ||
public void setLogMessageFormat() { | ||
P6SpyOptions.getActiveInstance().setLogMessageFormat(this.getClass().getName()); | ||
} | ||
|
||
@Override | ||
public String formatMessage(int connectionId, String now, long elapsed, String category, | ||
String prepared, String sql, String url) { | ||
sql = formatSql(category, sql); | ||
Date currentDate = new Date(); | ||
|
||
SimpleDateFormat formatter = new SimpleDateFormat("yy.MM.dd HH:mm:ss"); | ||
|
||
return category + " | " + "OperationTime : " + elapsed + "ms" + sql; | ||
} | ||
|
||
private String formatSql(String category, String sql) { | ||
if (sql == null || sql.isBlank()) { | ||
return sql; | ||
} | ||
|
||
if (Category.STATEMENT.getName().equals(category)) { | ||
String tmpsql = sql.trim().toLowerCase(Locale.ROOT); | ||
if (tmpsql.startsWith("create") || tmpsql.startsWith("alter")) { | ||
sql = FormatStyle.DDL.getFormatter().format(sql); | ||
} else { | ||
sql = FormatStyle.BASIC.getFormatter().format(sql); | ||
} | ||
sql = "\n" + stackTrace() + "\n" + sql + "\n"; | ||
} | ||
|
||
return sql; | ||
P6SpyOptions.getActiveInstance().setLogMessageFormat(P6spyMessageFormatter.class.getName()); | ||
} | ||
|
||
private String stackTrace() { | ||
return Arrays.toString(Arrays.stream(new Throwable().getStackTrace()) | ||
.filter(t -> t.toString().startsWith("com.prgrms.mukvengers")) | ||
.toArray()).replace(", ", "\n"); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/prgrms/mukvengers/global/config/p6spy/P6spyMessageFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.prgrms.mukvengers.global.config.p6spy; | ||
|
||
import java.util.Arrays; | ||
import java.util.Locale; | ||
|
||
import org.hibernate.engine.jdbc.internal.FormatStyle; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
import com.p6spy.engine.logging.Category; | ||
import com.p6spy.engine.spy.appender.MessageFormattingStrategy; | ||
|
||
@Profile("default") | ||
@Configuration | ||
public class P6spyMessageFormatter implements MessageFormattingStrategy { | ||
|
||
@Override | ||
public String formatMessage(int connectionId, String now, long elapsed, String category, | ||
String prepared, String sql, String url) { | ||
|
||
sql = formatSql(category, sql); | ||
return category + " | " + "OperationTime : " + elapsed + "ms" + sql; | ||
} | ||
|
||
private String formatSql(String category, String sql) { | ||
if (sql == null || sql.isBlank()) { | ||
return sql; | ||
} | ||
|
||
if (Category.STATEMENT.getName().equals(category)) { | ||
String tmpsql = sql.trim().toLowerCase(Locale.ROOT); | ||
if (tmpsql.startsWith("create") || tmpsql.startsWith("alter")) { | ||
sql = FormatStyle.DDL.getFormatter().format(sql); | ||
} else { | ||
sql = FormatStyle.BASIC.getFormatter().format(sql); | ||
} | ||
} | ||
|
||
sql += "\n"; | ||
|
||
String[] stackTrace = stackTrace(); | ||
|
||
if (stackTrace.length > 0) { | ||
sql += Arrays.toString(stackTrace).replace(", ", "\n"); | ||
} | ||
|
||
return sql; | ||
} | ||
|
||
private String[] stackTrace() { | ||
return Arrays.stream(new Throwable().getStackTrace()) | ||
.map(StackTraceElement::toString) | ||
.filter(string -> string.startsWith("com.prgrms.mukvengers") | ||
&& !string.startsWith("com.prgrms.mukvengers.global.config.p6spy") | ||
&& !string.startsWith("com.prgrms.mukvengers.MukvengersApplication.main")) | ||
.toArray(String[]::new); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/prgrms/mukvengers/global/utils/GeometryUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.prgrms.mukvengers.global.utils; | ||
|
||
import org.locationtech.jts.geom.GeometryFactory; | ||
import org.locationtech.jts.geom.PrecisionModel; | ||
|
||
public class GeometryUtils { | ||
|
||
private static final GeometryFactory INSTANCE | ||
= new GeometryFactory(new PrecisionModel(), 5179); | ||
|
||
private GeometryUtils() { | ||
/* no-op */ | ||
} | ||
|
||
public static GeometryFactory getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
// Meter -> radius | ||
public static double calculateApproximateRadius(int distanceInMeters) { | ||
// The approximate radius of the earth in meters | ||
double earthRadius = 6371000; | ||
|
||
// convert distance to radius in radians | ||
double radiusInRadians = distanceInMeters / earthRadius; | ||
|
||
// convert radians to degrees | ||
return Math.toDegrees(radiusInRadians); | ||
} | ||
|
||
} |
Oops, something went wrong.