Skip to content

Commit

Permalink
[RELEASE] v24.08.28.01 (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 authored Aug 28, 2024
2 parents ed640b5 + b63a9b1 commit 64d979a
Show file tree
Hide file tree
Showing 55 changed files with 983 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ package com.few.api.repo.dao.article
import com.few.api.repo.config.LocalCacheConfig.Companion.LOCAL_CM
import com.few.api.repo.config.LocalCacheConfig.Companion.SELECT_ARTICLE_RECORD_CACHE
import com.few.api.repo.dao.article.command.InsertFullArticleRecordCommand
import com.few.api.repo.dao.article.query.SelectArticleIdByWorkbookIdAndDayQuery
import com.few.api.repo.dao.article.query.SelectArticleRecordQuery
import com.few.api.repo.dao.article.query.SelectWorkBookArticleRecordQuery
import com.few.api.repo.dao.article.query.SelectWorkbookMappedArticleRecordsQuery
import com.few.api.repo.dao.article.record.SelectArticleContentsRecord
import com.few.api.repo.dao.article.record.SelectArticleRecord
import com.few.api.repo.dao.article.record.SelectWorkBookArticleRecord
import com.few.api.repo.dao.article.record.SelectWorkBookMappedArticleRecord
import com.few.api.repo.dao.article.query.*
import com.few.api.repo.dao.article.record.*
import com.few.data.common.code.MemberType
import jooq.jooq_dsl.tables.ArticleIfo
import jooq.jooq_dsl.tables.ArticleMst
import jooq.jooq_dsl.tables.MappingWorkbookArticle
import jooq.jooq_dsl.tables.Member
import org.jooq.*
import org.jooq.impl.DSL
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Repository

Expand Down Expand Up @@ -139,4 +136,31 @@ class ArticleDao(
).from(ArticleIfo.ARTICLE_IFO)
.where(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.`in`(articleIds))
.and(ArticleIfo.ARTICLE_IFO.DELETED_AT.isNull)

fun selectArticleContent(query: SelectArticleContentQuery): ArticleContentRecord? {
return selectArticleContentQuery(query)
.fetchOneInto(ArticleContentRecord::class.java)
}

fun selectArticleContentQuery(query: SelectArticleContentQuery) =
dslContext.select(
ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.`as`(ArticleContentRecord::id.name),
ArticleIfo.ARTICLE_IFO.CONTENT.`as`(ArticleContentRecord::articleContent.name),
ArticleMst.ARTICLE_MST.TITLE.`as`(ArticleContentRecord::articleTitle.name),
ArticleMst.ARTICLE_MST.CATEGORY_CD.`as`(ArticleContentRecord::category.name),
DSL.jsonGetAttributeAsText(Member.MEMBER.DESCRIPTION, "name")
.`as`(ArticleContentRecord::writerName.name),
DSL.jsonGetAttribute(Member.MEMBER.DESCRIPTION, "url")
.`as`(ArticleContentRecord::writerLink.name)
)
.from(ArticleIfo.ARTICLE_IFO)
.join(ArticleMst.ARTICLE_MST)
.on(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.eq(ArticleMst.ARTICLE_MST.ID))
.join(Member.MEMBER)
.on(
ArticleMst.ARTICLE_MST.MEMBER_ID.eq(Member.MEMBER.ID)
.and(Member.MEMBER.TYPE_CD.eq(MemberType.WRITER.code))
)
.where(ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.eq(query.articleId))
.and(ArticleIfo.ARTICLE_IFO.DELETED_AT.isNull)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.article.query

data class SelectArticleContentQuery(
val articleId: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.few.api.repo.dao.article.record

import java.net.URL

data class ArticleContentRecord(
val id: Long,
val category: String,
val articleTitle: String,
val articleContent: String,
val writerName: String,
val writerLink: URL,
)
17 changes: 12 additions & 5 deletions api-repo/src/main/kotlin/com/few/api/repo/dao/member/MemberDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import com.few.api.repo.config.LocalCacheConfig.Companion.LOCAL_CM
import com.few.api.repo.config.LocalCacheConfig.Companion.SELECT_WRITER_CACHE
import com.few.api.repo.dao.member.command.DeleteMemberCommand
import com.few.api.repo.dao.member.command.InsertMemberCommand
import com.few.api.repo.dao.member.query.BrowseWorkbookWritersQuery
import com.few.api.repo.dao.member.command.UpdateDeletedMemberTypeCommand
import com.few.api.repo.dao.member.command.UpdateMemberTypeCommand
import com.few.api.repo.dao.member.query.SelectMemberByEmailNotConsiderDeletedAtQuery
import com.few.api.repo.dao.member.query.SelectMemberByEmailQuery
import com.few.api.repo.dao.member.query.SelectWriterQuery
import com.few.api.repo.dao.member.query.SelectWritersQuery
import com.few.api.repo.dao.member.query.*
import com.few.api.repo.dao.member.record.MemberIdAndIsDeletedRecord
import com.few.api.repo.dao.member.record.MemberRecord
import com.few.api.repo.dao.member.record.MemberEmailAndTypeRecord
Expand Down Expand Up @@ -171,6 +167,17 @@ class MemberDao(
.set(Member.MEMBER.EMAIL, command.email)
.set(Member.MEMBER.TYPE_CD, command.memberType.code)

fun selectMemberEmail(query: SelectMemberEmailQuery): String? {
return selectMemberEmailQuery(query)
.fetchOne()
?.value1()
}

fun selectMemberEmailQuery(query: SelectMemberEmailQuery) = dslContext.select(Member.MEMBER.EMAIL)
.from(Member.MEMBER)
.where(Member.MEMBER.ID.eq(query.memberId))
.and(Member.MEMBER.DELETED_AT.isNull)

fun selectMemberEmailAndType(memberId: Long): MemberEmailAndTypeRecord? {
return selectMemberIdAndTypeQuery(memberId)
.fetchOne()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.member.query

data class SelectMemberEmailQuery(
val memberId: Long,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.few.api.repo.dao.subscription

import com.few.api.repo.dao.subscription.command.InsertWorkbookSubscriptionCommand
import com.few.api.repo.dao.subscription.command.UpdateDeletedAtInAllSubscriptionCommand
import com.few.api.repo.dao.subscription.command.UpdateDeletedAtInWorkbookSubscriptionCommand
import com.few.api.repo.dao.subscription.command.*
import com.few.api.repo.dao.subscription.query.*
import com.few.api.repo.dao.subscription.record.WorkbookSubscriptionStatus
import com.few.api.repo.dao.subscription.record.CountAllSubscriptionStatusRecord
Expand Down Expand Up @@ -163,4 +161,28 @@ class SubscriptionDao(
.from(SUBSCRIPTION)
.groupBy(SUBSCRIPTION.TARGET_WORKBOOK_ID)
.query

fun updateArticleProgress(command: UpdateArticleProgressCommand) {
updateArticleProgressCommand(command)
.execute()
}

fun updateArticleProgressCommand(
command: UpdateArticleProgressCommand,
) = dslContext.update(SUBSCRIPTION)
.set(SUBSCRIPTION.PROGRESS, SUBSCRIPTION.PROGRESS.add(1))
.where(SUBSCRIPTION.MEMBER_ID.eq(command.memberId))
.and(SUBSCRIPTION.TARGET_WORKBOOK_ID.eq(command.workbookId))

fun updateLastArticleProgress(command: UpdateLastArticleProgressCommand) {
updateLastArticleProgressCommand(command)
.execute()
}

fun updateLastArticleProgressCommand(command: UpdateLastArticleProgressCommand) =
dslContext.update(SUBSCRIPTION)
.set(SUBSCRIPTION.DELETED_AT, LocalDateTime.now())
.set(SUBSCRIPTION.UNSUBS_OPINION, command.opinion)
.where(SUBSCRIPTION.MEMBER_ID.eq(command.memberId))
.and(SUBSCRIPTION.TARGET_WORKBOOK_ID.eq(command.workbookId))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.few.api.repo.dao.subscription.command

data class UpdateArticleProgressCommand(
val memberId: Long,
val workbookId: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.few.api.repo.dao.subscription.command

data class UpdateLastArticleProgressCommand(
val memberId: Long,
val workbookId: Long,
val opinion: String = "receive.all",
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.few.api.repo.config.LocalCacheConfig.Companion.LOCAL_CM
import com.few.api.repo.dao.workbook.command.InsertWorkBookCommand
import com.few.api.repo.dao.workbook.command.MapWorkBookToArticleCommand
import com.few.api.repo.dao.workbook.query.BrowseWorkBookQueryWithSubscriptionCount
import com.few.api.repo.dao.workbook.query.SelectWorkBookLastArticleIdQuery
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery
import com.few.api.repo.dao.workbook.record.SelectWorkBookRecord
import com.few.api.repo.dao.workbook.record.SelectWorkBookRecordWithSubscriptionCount
Expand Down Expand Up @@ -129,4 +130,18 @@ class WorkbookDao(
else -> Workbook.WORKBOOK.CATEGORY_CD.eq(query.category)
}
}

fun selectWorkBookLastArticleId(query: SelectWorkBookLastArticleIdQuery): Long? {
return selectWorkBookLastArticleIdQuery(query)
.fetchOneInto(Long::class.java)
}

fun selectWorkBookLastArticleIdQuery(query: SelectWorkBookLastArticleIdQuery) =
dslContext.select(
DSL.max(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.DAY_COL)
)
.from(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE)
.where(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.WORKBOOK_ID.eq(query.workbookId))
.and(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.DELETED_AT.isNull)
.groupBy(MappingWorkbookArticle.MAPPING_WORKBOOK_ARTICLE.WORKBOOK_ID)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.few.api.repo.dao.workbook.query

data class SelectWorkBookLastArticleIdQuery(
val workbookId: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.few.api.repo.explain

import org.jooq.DSLContext
import org.jooq.Query

class ExplainGenerator {
companion object {
/**
* Execute EXPLAIN and EXPLAIN ANALYZE FORMAT=TREE
*/
fun execute(dslContext: DSLContext, query: Query): String {
val sql = query.sql
val values = query.bindValues
mapSqlAndValues(sql, values).let {
val explain = StringBuilder()
explain.append("EXPLAIN $it\n")
explain.append("\n")
dslContext.fetch("EXPLAIN $it").let {
explain.append(it)
}
explain.append("\n\n")
explain.append("EXPLAIN ANALYZE FORMAT=TREE $it\n")
explain.append("\n")
dslContext.fetch("EXPLAIN ANALYZE FORMAT=TREE $it").let {
it.forEach { record ->
explain.append(record[0].toString())
}
}
return explain.toString()
}
}

/**
* Execute EXPLAIN
*/
fun explain(dslContext: DSLContext, query: Query): String {
val sql = query.sql
val values = query.bindValues
mapSqlAndValues(sql, values).let {
val explain = StringBuilder()
explain.append("EXPLAIN $it\n")
explain.append("\n")
dslContext.fetch("EXPLAIN $it").let {
explain.append(it)
}
return explain.toString()
}
}

/**
* Execute EXPLAIN ANALYZE FORMAT=TREE
*/
fun analyzeFormatTree(dslContext: DSLContext, query: Query): String {
val sql = query.sql
val values = query.bindValues
mapSqlAndValues(sql, values).let {
val explain = StringBuilder()
explain.append("EXPLAIN ANALYZE FORMAT=TREE $it\n")
explain.append("\n")
dslContext.fetch("EXPLAIN ANALYZE FORMAT=TREE $it").let {
it.forEach { record ->
explain.append(record[0].toString())
}
}
return explain.toString()
}
}

private fun mapSqlAndValues(sql: String, values: List<Any>) =
values.foldIndexed(sql) { index, acc, value ->
if (value is String) {
acc.replaceFirst("?", "'$value'")
} else {
acc.replaceFirst("?", "$value")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.few.api.repo.dao.article.query.SelectArticleIdByWorkbookIdAndDayQuery
import com.few.api.repo.dao.article.query.SelectArticleRecordQuery
import com.few.api.repo.dao.article.query.SelectWorkBookArticleRecordQuery
import com.few.api.repo.dao.article.query.SelectWorkbookMappedArticleRecordsQuery
import com.few.api.repo.explain.ExplainGenerator
import com.few.api.repo.explain.InsertUpdateExplainGenerator
import com.few.api.repo.explain.ResultGenerator
import com.few.api.repo.jooq.JooqTestSpec
Expand Down Expand Up @@ -63,7 +64,7 @@ class ArticleDaoExplainGenerateTest : JooqTestSpec() {
articleDao.selectArticleRecordQuery(it)
}

val explain = dslContext.explain(query).toString()
val explain = ExplainGenerator.execute(dslContext, query)

ResultGenerator.execute(query, explain, "selectArticleRecordQueryExplain")
}
Expand All @@ -74,7 +75,7 @@ class ArticleDaoExplainGenerateTest : JooqTestSpec() {
articleDao.selectWorkBookArticleRecordQuery(it)
}

val explain = dslContext.explain(query).toString()
val explain = ExplainGenerator.execute(dslContext, query)

ResultGenerator.execute(query, explain, "selectWorkBookArticleRecordQueryExplain")
}
Expand All @@ -85,7 +86,7 @@ class ArticleDaoExplainGenerateTest : JooqTestSpec() {
articleDao.selectWorkbookMappedArticleRecordsQuery(it)
}

val explain = dslContext.explain(query).toString()
val explain = ExplainGenerator.execute(dslContext, query)

ResultGenerator.execute(query, explain, "selectWorkbookMappedArticleRecordsQueryExplain")
}
Expand Down Expand Up @@ -130,7 +131,7 @@ class ArticleDaoExplainGenerateTest : JooqTestSpec() {
articleDao.selectArticleIdByWorkbookIdAndDayQuery(it)
}

val explain = dslContext.explain(query).toString()
val explain = ExplainGenerator.execute(dslContext, query)

ResultGenerator.execute(query, explain, "selectArticleIdByWorkbookIdAndDayQueryExplain")
}
Expand All @@ -141,7 +142,7 @@ class ArticleDaoExplainGenerateTest : JooqTestSpec() {
articleDao.selectArticleContentsQuery(it)
}

val explain = dslContext.explain(query).toString()
val explain = ExplainGenerator.execute(dslContext, query)

ResultGenerator.execute(query, explain, "selectArticleContentsQueryExplain")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.few.api.repo.dao.article.ArticleMainCardDao
import com.few.api.repo.dao.article.command.ArticleMainCardExcludeWorkbookCommand
import com.few.api.repo.dao.article.command.UpdateArticleMainCardWorkbookCommand
import com.few.api.repo.dao.article.command.WorkbookCommand
import com.few.api.repo.explain.ExplainGenerator
import com.few.api.repo.explain.InsertUpdateExplainGenerator
import com.few.api.repo.explain.ResultGenerator
import com.few.api.repo.jooq.JooqTestSpec
import com.few.data.common.code.CategoryType
Expand Down Expand Up @@ -59,7 +61,7 @@ class ArticleMainCardDaoExplainGenerateTest : JooqTestSpec() {
fun selectArticleMainCardsRecordQueryExplain() {
val query = articleMainCardDao.selectArticleMainCardsRecordQuery(setOf(1L))

val explain = dslContext.explain(query).toString()
val explain = ExplainGenerator.execute(dslContext, query)
ResultGenerator.execute(query, explain, "selectArticleMainCardsRecordQueryExplain")
}

Expand All @@ -80,7 +82,7 @@ class ArticleMainCardDaoExplainGenerateTest : JooqTestSpec() {
articleMainCardDao.insertArticleMainCardCommand(it)
}

val explain = command.toString()
val explain = InsertUpdateExplainGenerator.execute(dslContext, command.sql, command.bindValues)

ResultGenerator.execute(command, explain, "insertArticleMainCardCommandExplain")
}
Expand All @@ -103,7 +105,7 @@ class ArticleMainCardDaoExplainGenerateTest : JooqTestSpec() {
articleMainCardDao.updateArticleMainCardSetWorkbookCommand(it)
}

val explain = command.toString()
val explain = InsertUpdateExplainGenerator.execute(dslContext, command.sql, command.bindValues)

ResultGenerator.execute(command, explain, "updateArticleMainCardSetWorkbookCommandExplain")
}
Expand Down
Loading

0 comments on commit 64d979a

Please sign in to comment.