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

[Refactor/query] 게시글, 빈집, 사용자 테이블 인덱스 추가 ( BTREE 방식 ) 및 조회 쿼리 튜닝 #307

Merged
merged 5 commits into from
Nov 2, 2023
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
9 changes: 4 additions & 5 deletions .github/workflows/CD-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ jobs:

steps:
#jdk 세팅
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
java-version: 17
distribution: 'zulu'

#gradle 캐싱
- name: Gradle Caching
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ jobs:

steps:
#jdk 세팅
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
java-version: 17
distribution: 'zulu'

#gradle 캐싱
- name: Gradle Caching
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/CI-Sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'temurin' # Alternative distribution options are available
java-version: 17
distribution: 'zulu'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ jobs:

steps:
#jdk 세팅
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
java-version: 17
distribution: 'zulu'

#gradle 캐싱
- name: Gradle Caching
Expand Down
5 changes: 2 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.kapt3.base.Kapt.kapt

plugins {
id("org.springframework.boot") version "2.7.8"
Expand Down Expand Up @@ -30,7 +29,7 @@ sonarqube {

group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
mavenCentral()
Expand Down Expand Up @@ -87,7 +86,7 @@ dependencies {
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "11"
jvmTarget = "17"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.example.jhouse_server.domain.comment.dto.CommentResDto
import java.sql.Timestamp
import java.util.*
import javax.validation.constraints.NotNull
import kotlin.streams.toList
/**
* =============================================================================================
* REQUEST DTO
Expand Down Expand Up @@ -84,6 +83,12 @@ fun toListDto(board : Board) : BoardResDto {
fun toDto(board: Board) : BoardResOneDto {
return BoardResOneDto(board.id, board.title, board.boardCode.code, board.user.nickName, Timestamp.valueOf(board.createdAt), board.imageUrls, board.love.size, board.category.name, board.prefixCategory.name, board.comment.size, board.comment.stream().map { com.example.jhouse_server.domain.comment.dto.toDto(it) }.toList())
}

/**
* =============================================================================================
* UTIL FUNCTION
* =============================================================================================
* */
fun sliceContentWithRegex(content : String) : String {
return if (content.length >= 200) {
content.take(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import javax.persistence.*

@Entity
@Table(
name = "board"
name = "board", indexes = [Index(name = "idx__prefixCategory__category", columnList = "category, prefixCategory, useYn")]
)
class Board(
var title: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class BoardRepositoryImpl(
override fun getBoardAll(boardListDto: BoardListDto, pageable: Pageable): Page<BoardResDto> {
val result = jpaQueryFactory
.selectFrom(board)
.join(board.boardCode, boardCode).fetchJoin()
.join(board.user, user).fetchJoin()
.join(board.boardCode, boardCode)
.join(board.user, user)
.leftJoin(board.comment, comment)
.where(
board.useYn.eq(true),
Expand All @@ -114,6 +114,9 @@ class BoardRepositoryImpl(
.fetch()
val countQuery = jpaQueryFactory
.selectFrom(board)
.join(board.boardCode, boardCode)
.join(board.user, user)
.leftJoin(board.comment, comment)
.where(
board.useYn.eq(true),
filterWithPrefixCategory(boardListDto.prefix),
Expand Down Expand Up @@ -190,6 +193,7 @@ class BoardRepositoryImpl(
.fetch()
val countQuery = jpaQueryFactory
.selectFrom(board).distinct()
.join(board.comment, comment)
.where(
board.useYn.eq(true),
comment.user.eq(user)
Expand Down Expand Up @@ -217,6 +221,7 @@ class BoardRepositoryImpl(
.fetch()
val countQuery = jpaQueryFactory
.selectFrom(board).distinct()
.join(board.love, love)
.where(
board.useYn.eq(true),
love.user.eq(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import java.sql.Timestamp
import java.util.*
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import kotlin.streams.toList

/**
* ================================================================================================
Expand Down Expand Up @@ -79,7 +78,7 @@ data class MyHouseResDto(
* 빈집 매물 게시글 리스트 조회 시, 응답 DTO
* ================================================================================================
* */
class HouseResDto() {
class HouseResDto() : Serializable {
var houseId: Long = 0 // 게시글 아이디
lateinit var rentalType: RentalType // 매물 유형
lateinit var city: String // 매물 위치
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.example.jhouse_server.domain.house.entity

import com.example.jhouse_server.domain.board.entity.*
import com.example.jhouse_server.domain.board.entity.BoardImageUrlConverter
import com.example.jhouse_server.domain.scrap.entity.Scrap
import com.example.jhouse_server.domain.user.entity.User
import com.example.jhouse_server.global.entity.BaseEntity
import javax.persistence.*

@Table(name = "house",
indexes = [Index(name = "idx__rental_type", columnList = "rentalType, useYn, tmpYn, reported, applied"),
Index(name = "idx__title", columnList = "title, useYn, tmpYn, reported, applied")
])
@Entity
class House(
@Convert(converter = RentalTypeConverter::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class HouseRepositoryImpl(

val countQuery : Long = jpaQueryFactory
.selectFrom(house)
.innerJoin(house.user)
.leftJoin(house.houseTag)
.where(
house.useYn.eq(true), // 삭제 X
searchWithRentalType(houseListDto.rentalType),
Expand Down Expand Up @@ -97,6 +99,7 @@ class HouseRepositoryImpl(

val countQuery : Long = jpaQueryFactory
.selectFrom(house)
.innerJoin(house.user)
.where(
house.useYn.eq(true), // 삭제 X
house.reported.eq(false), // 신고 X
Expand All @@ -115,7 +118,7 @@ class HouseRepositoryImpl(
override fun getScrapHouseAll(user: User, filter: String?, pageable: Pageable): Page<House> {
val result = jpaQueryFactory
.selectFrom(house)
.join(house.user, QUser.user).fetchJoin()
.join(house.user, QUser.user)
.join(house.scrap, scrap)
.where(
house.useYn.eq(true), // 삭제 X
Expand All @@ -128,6 +131,8 @@ class HouseRepositoryImpl(
.fetch()
val countQuery = jpaQueryFactory
.selectFrom(house)
.join(house.user, QUser.user)
.join(house.scrap, scrap)
.where(
house.useYn.eq(true), // 삭제 X
house.reported.eq(false), // 신고 X
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package com.example.jhouse_server.domain.user.entity

import com.example.jhouse_server.domain.board.entity.Board
import com.example.jhouse_server.domain.scrap.entity.Scrap
import com.example.jhouse_server.domain.comment.entity.Comment
import com.example.jhouse_server.domain.house.entity.House
import com.example.jhouse_server.domain.notification.entity.Notification
import com.example.jhouse_server.domain.record.entity.Record
import com.example.jhouse_server.domain.record_comment.entity.RecordComment
import com.example.jhouse_server.domain.record_review.entity.RecordReview
import com.example.jhouse_server.domain.record_review_apply.entity.RecordReviewApply
import com.example.jhouse_server.domain.scrap.entity.Scrap
import com.example.jhouse_server.domain.user.WithdrawalUser
import com.example.jhouse_server.domain.user.entity.WithdrawalStatus.*
import com.example.jhouse_server.domain.user.entity.WithdrawalStatus.APPROVE
import com.example.jhouse_server.global.entity.BaseEntity
import org.springframework.util.StringUtils
import javax.persistence.*

@Table(name = "user",
indexes = [Index(name = "idx__email", columnList = "email"),
Index(name = "idx__nick_name", columnList = "nickName")
])
@Entity
@DiscriminatorValue("U")
class User(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UserRepositoryImpl(
val total = jpaQueryFactory
.selectFrom(user)
.where(user.authority.eq(Authority.USER))
.fetch().size.toLong()
.fetch().size.toLong()

return getOrderAgeRateResult(queryResult, total)
}
Expand All @@ -66,7 +66,7 @@ class UserRepositoryImpl(
.selectFrom(userJoinPath)
.join(userJoinPath.user, user)
.where(user.authority.eq(Authority.USER))
.fetch().size.toLong()
.fetch().size.toLong()

return getOrderJoinPathRateResult(queryResult, total)
}
Expand Down