-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: flyway V1.00.0.7 배포(ARTICLE_VIEW_HIS 테이블 추가) * feat: article view history 저장 로직 추가 * feat: article 조회시 views 필드 추가 * test: article 조회수 추가 관련 test 코드 수정 * feat: ARTICLE_VIEW_HIS 테이블 인덱스 추가(article_mst_id 컬럼) * fix: 인덱스 테이블 명 수정 * refactor: DAO 메소드 명 수정 * refactor: 아티클 뷰와 아티클 도메인 통합 * refactor: DAO 빈 지정 stereotype 변경(@component -> @repository) * refactor: 조회수 결정에 대한 로직을 DAO -> UC로 이동 * chore: member Id 사용에 대한 TODO 주석 추가 * feat: 아티클 조회 기록 Insert과정을 다른 쓰레드에서 수행하도록 변경 * fix: add ArticleViewHisAsyncEvent * test: ReadArticleUseCaseTest 수정반영 * refactor: SubscribeWorkbookUseCaseTest 에서 print 삭제 및 log 적용 * refactor: rename ArticleViewHisAsyncHandler * test: application-test.yaml에 database async thread pool 설정 추가 * fix: 테스트 통과하지 못하는 문제 해결 * feat: 아티클 조회응답 바디 views 필드 추가 --------- Co-authored-by: belljun3395 <[email protected]>
- Loading branch information
1 parent
4c8c4ce
commit 7ffe45c
Showing
27 changed files
with
213 additions
and
35 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 was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleViewHisDao.kt
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.few.api.repo.dao.article | ||
|
||
import com.few.api.repo.dao.article.command.ArticleViewHisCommand | ||
import com.few.api.repo.dao.article.query.ArticleViewHisCountQuery | ||
import jooq.jooq_dsl.tables.ArticleViewHis | ||
import org.jooq.DSLContext | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class ArticleViewHisDao( | ||
private val dslContext: DSLContext, | ||
) { | ||
|
||
fun insertArticleViewHis(command: ArticleViewHisCommand) { | ||
dslContext.insertInto( | ||
ArticleViewHis.ARTICLE_VIEW_HIS, | ||
ArticleViewHis.ARTICLE_VIEW_HIS.ARTICLE_MST_ID, | ||
ArticleViewHis.ARTICLE_VIEW_HIS.MEMBER_ID | ||
).values( | ||
command.articleId, | ||
command.memberId | ||
).execute() | ||
} | ||
|
||
fun countArticleViews(query: ArticleViewHisCountQuery): Long? { | ||
return dslContext.selectCount() | ||
.from(ArticleViewHis.ARTICLE_VIEW_HIS) | ||
.where(ArticleViewHis.ARTICLE_VIEW_HIS.ARTICLE_MST_ID.eq(query.articleId)) | ||
.fetchOne(0, Long::class.java) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
api-repo/src/main/kotlin/com/few/api/repo/dao/article/command/ArticleViewHisCommand.kt
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,6 @@ | ||
package com.few.api.repo.dao.article.command | ||
|
||
data class ArticleViewHisCommand( | ||
val articleId: Long, | ||
val memberId: Long, | ||
) |
5 changes: 5 additions & 0 deletions
5
api-repo/src/main/kotlin/com/few/api/repo/dao/article/query/ArticleViewHisCountQuery.kt
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,5 @@ | ||
package com.few.api.repo.dao.article.query | ||
|
||
data class ArticleViewHisCountQuery( | ||
val articleId: Long, | ||
) |
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 was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
api/src/main/kotlin/com/few/api/config/DatabaseAccessThreadPoolConfig.kt
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,38 @@ | ||
package com.few.api.config | ||
|
||
import com.few.api.config.properties.ThreadPoolProperties | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor | ||
|
||
@Configuration | ||
class DatabaseAccessThreadPoolConfig { | ||
private val log = KotlinLogging.logger {} | ||
|
||
companion object { | ||
const val DATABASE_ACCESS_POOL = "database-task-" | ||
} | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix = "database.thread-pool") | ||
fun databaseAccessThreadPoolProperties(): ThreadPoolProperties { | ||
return ThreadPoolProperties() | ||
} | ||
|
||
@Bean(DATABASE_ACCESS_POOL) | ||
fun databaseAccessThreadPool() = ThreadPoolTaskExecutor().apply { | ||
val properties = databaseAccessThreadPoolProperties() | ||
corePoolSize = properties.getCorePoolSize() | ||
maxPoolSize = properties.getMaxPoolSize() | ||
queueCapacity = properties.getQueueCapacity() | ||
setWaitForTasksToCompleteOnShutdown(properties.getWaitForTasksToCompleteOnShutdown()) | ||
setAwaitTerminationSeconds(properties.getAwaitTerminationSeconds()) | ||
setThreadNamePrefix("databaseAccessThreadPool-") | ||
setRejectedExecutionHandler { r, _ -> | ||
log.warn { "Database Access Task Rejected: $r" } | ||
} | ||
initialize() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
api/src/main/kotlin/com/few/api/domain/article/handler/ArticleViewHisAsyncHandler.kt
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,27 @@ | ||
package com.few.api.domain.article.handler | ||
|
||
import com.few.api.config.DatabaseAccessThreadPoolConfig.Companion.DATABASE_ACCESS_POOL | ||
import com.few.api.repo.dao.article.ArticleViewHisDao | ||
import com.few.api.repo.dao.article.command.ArticleViewHisCommand | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class ArticleViewHisAsyncHandler( | ||
private val articleViewHisDao: ArticleViewHisDao, | ||
) { | ||
private val log = KotlinLogging.logger {} | ||
|
||
@Async(value = DATABASE_ACCESS_POOL) | ||
@Transactional | ||
fun addArticleViewHis(articleId: Long, memberId: Long) { | ||
try { | ||
articleViewHisDao.insertArticleViewHis(ArticleViewHisCommand(articleId, memberId)) | ||
log.debug { "Successfully inserted article view history for articleId: $articleId and memberId: $memberId" } | ||
} catch (e: Exception) { | ||
log.error { "Failed to insert article view history for articleId: $articleId and memberId: $memberId" } | ||
} | ||
} | ||
} |
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
Oops, something went wrong.