Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#22] Transaction 발생 시 DB 저장 개선 #23

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'



}
2 changes: 2 additions & 0 deletions application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ spring:
ddl-auto: update
show-sql: false
generate-ddl: true
flyway:
sqlMigrationSeparator: "//"
main:
web-application-type: servlet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,10 @@ public Transaction getTransactionById(int id) {
}

public Transaction createTransaction(Transaction tx) {
long start = System.currentTimeMillis();
Transaction savedTx = transactionRepository.save(tx);

// 트랜잭션 저장 후 시점
long startAlertTime = System.currentTimeMillis();

// AlertSetting 조회
List<AlertSetting> settings = alertRepository.findByCoin(savedTx.getCoin());

// 임계값 비교
for (AlertSetting setting : settings) {
if (savedTx.getTradeVolume() >= setting.getThreshold()) {
// 임계값 초과 UserAlert 생성
UserAlert userAlert = new UserAlert(
setting.getUserId(),
savedTx.getCoin(),
savedTx.getTradePrice(),
savedTx.getTradeVolume(),
savedTx.getTradeTimestamp()
);
userAlertService.createUserAlert(userAlert);
}
}
// Alert db 저장 후 시점
long endAlertTime = System.currentTimeMillis();

long alertInsertionTime = endAlertTime - startAlertTime;
log.info("Transaction save {}ms",alertInsertionTime);
long duration = System.currentTimeMillis() - start;
log.info("Alert savs {} ms", duration);
return savedTx;
}

Expand Down