Skip to content

Commit

Permalink
Merge pull request #120 from GSM-MSG/119-feat/data-init-count
Browse files Browse the repository at this point in the history
#119 DataInitializer 데이터 존재 여부 count 쿼리 성능 개선
  • Loading branch information
esperar authored Nov 10, 2023
2 parents 84db914 + 0bd5135 commit b6d0e56
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class DataInitializer(

/**
* ApplicationReadyEvent가 발행되면 initData가 실행됩니다.
* school, club의 데이터 count가 0이라면 데이터 삽입이 실행됩니다.
* school, club id = 1인 엔티티가 존재하면 Data Init을 실행하지 않는다.
*/
@EventListener(ApplicationReadyEvent::class)
@Transactional
fun initData() {
if(schoolRepository.count() == 0L) {
if(schoolRepository.existsOne(1)) {
log.info("=== RUN Init School Data ===")
initSchool()
}

if(clubRepository.count() == 0L) {
if(clubRepository.existsOne(1)) {
log.info("=== RUN Init Club Data ===")
initClub()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.Query
import team.msg.domain.club.model.Club
import team.msg.domain.school.model.School

interface ClubRepository : JpaRepository<Club, Long> {
interface ClubRepository : JpaRepository<Club, Long>, CustomClubRepository {
@EntityGraph(attributePaths = ["school"], type = EntityGraph.EntityGraphType.FETCH)
fun findByNameAndSchool(name: String, school: School): Club?

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.msg.domain.club.repository

interface CustomClubRepository {
fun existsOne(id: Long): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.msg.domain.club.repository

import com.querydsl.jpa.impl.JPAQueryFactory
import team.msg.domain.club.model.QClub.club

class CustomClubRepositoryImpl(
private val queryFactory: JPAQueryFactory
) : CustomClubRepository {

override fun existsOne(id: Long): Boolean {
val fetchOne = queryFactory.selectOne()
.from(club)
.where(club.id.eq(id))
.fetchFirst() // limit 1

return fetchOne != null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.msg.domain.school.repository

interface CustomSchoolRepository {
fun existsOne(id: Long): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package team.msg.domain.school.repository

import com.querydsl.jpa.impl.JPAQueryFactory
import team.msg.domain.school.model.QSchool.school

class CustomSchoolRepositoryImpl(
private val queryFactory: JPAQueryFactory
) : CustomSchoolRepository {

override fun existsOne(id: Long): Boolean {
val fetchOne = queryFactory.selectOne()
.from(school)
.where(school.id.eq(id))
.fetchFirst() // limit 1

return fetchOne != null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import org.springframework.data.repository.CrudRepository
import team.msg.domain.school.enums.HighSchool
import team.msg.domain.school.model.School

interface SchoolRepository : CrudRepository<School, Long> {
interface SchoolRepository : CrudRepository<School, Long>, CustomSchoolRepository {
fun findByHighSchool(highSchool: HighSchool): School?
}
12 changes: 6 additions & 6 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/bin/bash
BUILD_JAR=$(ls /home/ec2-user/Bitgouel-Server/bitgouel-api/build/libs/*.jar)
JAR_NAME=$(basename $BUILD_JAR)
echo "> build 파일명: $JAR_NAME" >> /home/ec2-user/action/deploy.log
echo "> build 파일명: $JAR_NAME" >> /home/ec2-user/deploy.log

echo "> build 파일 복사" >> /home/ec2-user/action/deploy.log
DEPLOY_PATH=/home/ec2-user/action/
echo "> build 파일 복사" >> /home/ec2-user/deploy.log
DEPLOY_PATH=/home/ec2-user/
cp $BUILD_JAR $DEPLOY_PATH

echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ec2-user/action/deploy.log
echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ec2-user/deploy.log
CURRENT_PID=$(pgrep -f $JAR_NAME)

if [ -z $CURRENT_PID ]
then
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ec2-user/action/deploy.log
echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ec2-user/deploy.log
else
echo "> kill -15 $CURRENT_PID"
kill -15 $CURRENT_PID
sleep 5
fi

DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
echo "> DEPLOY_JAR 배포" >> /home/ec2-user/action/deploy.log
echo "> DEPLOY_JAR 배포" >> /home/ec2-user/deploy.log
nohup java -jar $DEPLOY_JAR --logging.file.path=/home/ec2-user/ --logging.level.org.hibernate.SQL=DEBUG >> /home/ec2-user/deploy.log 2>/home/ec2-user/deploy_err.log &

0 comments on commit b6d0e56

Please sign in to comment.