From 628202e39202e3831c868dd8f3c768125d6d5cff Mon Sep 17 00:00:00 2001 From: mingshewhe Date: Mon, 5 Aug 2024 21:25:24 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=96=B0=E5=BB=BA/=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=97=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=B5=81=E6=B0=B4=E7=BA=BF=20#8164=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9E=84=E5=BB=BA=E5=8E=86=E5=8F=B2=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=BA=90=E6=9D=90=E6=96=99=E5=88=86=E6=94=AF=E5=92=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=86=E6=94=AF=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 构建历史支持源材料和触发材料搜索 2. 触发分支和源材料分支支持下来搜索 使用服务内存搜索代替mysql搜索 --- .../process/engine/dao/PipelineBuildDao.kt | 158 ++---------------- .../engine/service/PipelineRuntimeService.kt | 14 +- 2 files changed, 20 insertions(+), 152 deletions(-) diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt index 4021f20e438..8c6e707546e 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/dao/PipelineBuildDao.kt @@ -73,7 +73,7 @@ class PipelineBuildDao { companion object { private val mapper = PipelineBuildInfoJooqMapper() private val debugMapper = PipelineDebugBuildInfoJooqMapper() - private const val DEFAULT_PAGE_SIZE = 100 + private const val DEFAULT_PAGE_SIZE = 50 } fun create(dslContext: DSLContext, startBuildContext: StartBuildContext) { @@ -1290,126 +1290,6 @@ class PipelineBuildDao { } } - private fun TPipelineBuildHistory.makeSearchOptionsCondition( - where: SelectConditionStep<*>, - type: HistorySearchType, - materialAlias: List? = null, - materialBranch: String? = null, - triggerAlias: List? = null, - triggerBranch: String? = null - ) { - when (type) { - HistorySearchType.MATERIAL -> - where.and(MATERIAL.isNotNull) - - HistorySearchType.TRIGGER -> - where.and(WEBHOOK_INFO.isNotNull) - } - if (!materialAlias.isNullOrEmpty() && materialAlias.first().isNotBlank()) { - var conditionsOr: Condition - - conditionsOr = JooqUtils.jsonExtract(t1 = MATERIAL, t2 = "\$[*].aliasName", lower = true) - .like("%${materialAlias.first().lowercase()}%") - - materialAlias.forEachIndexed { index, s -> - if (index == 0) return@forEachIndexed - conditionsOr = conditionsOr.or( - JooqUtils.jsonExtract(MATERIAL, "\$[*].aliasName", lower = true) - .like("%${s.lowercase()}%") - ) - } - where.and(conditionsOr) - } - if (!materialBranch.isNullOrBlank()) { - where.and( - JooqUtils.jsonExtract(MATERIAL, "\$[*].branchName", lower = true) - .like("%${materialBranch.lowercase()}%") - ) - } - if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { - var conditionsOr: Condition - - conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) - .like("%${triggerAlias.first().lowercase()}%") - - triggerAlias.forEachIndexed { index, s -> - if (index == 0) return@forEachIndexed - conditionsOr = conditionsOr.or( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) - .like("%${s.lowercase()}%") - ) - } - where.and(conditionsOr) - } - - if (!triggerBranch.isNullOrBlank()) { - where.and( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) - .like("%${triggerBranch.lowercase()}%") - ) - } - } - - private fun TPipelineBuildHistoryDebug.makeSearchOptionsDebugCondition( - where: SelectConditionStep<*>, - type: HistorySearchType, - materialAlias: List? = null, - materialBranch: String? = null, - triggerAlias: List? = null, - triggerBranch: String? = null - ) { - when (type) { - HistorySearchType.MATERIAL -> - where.and(MATERIAL.isNotNull) - - HistorySearchType.TRIGGER -> - where.and(WEBHOOK_INFO.isNotNull) - } - if (!materialAlias.isNullOrEmpty() && materialAlias.first().isNotBlank()) { - var conditionsOr: Condition - - conditionsOr = JooqUtils.jsonExtract(t1 = MATERIAL, t2 = "\$[*].aliasName", lower = true) - .like("%${materialAlias.first().lowercase()}%") - - materialAlias.forEachIndexed { index, s -> - if (index == 0) return@forEachIndexed - conditionsOr = conditionsOr.or( - JooqUtils.jsonExtract(MATERIAL, "\$[*].aliasName", lower = true) - .like("%${s.lowercase()}%") - ) - } - where.and(conditionsOr) - } - if (!materialBranch.isNullOrBlank()) { - where.and( - JooqUtils.jsonExtract(MATERIAL, "\$[*].branchName", lower = true) - .like("%${materialBranch.lowercase()}%") - ) - } - if (!triggerAlias.isNullOrEmpty() && triggerAlias.first().isNotBlank()) { - var conditionsOr: Condition - - conditionsOr = JooqUtils.jsonExtract(t1 = WEBHOOK_INFO, t2 = "\$.webhookAliasName", lower = true) - .like("%${triggerAlias.first().lowercase()}%") - - triggerAlias.forEachIndexed { index, s -> - if (index == 0) return@forEachIndexed - conditionsOr = conditionsOr.or( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookAliasName", lower = true) - .like("%${s.lowercase()}%") - ) - } - where.and(conditionsOr) - } - - if (!triggerBranch.isNullOrBlank()) { - where.and( - JooqUtils.jsonExtract(WEBHOOK_INFO, "\$.webhookBranch", lower = true) - .like("%${triggerBranch.lowercase()}%") - ) - } - } - private fun TPipelineBuildHistoryDebug.makeDebugCondition( where: SelectConditionStep<*>, materialAlias: List?, @@ -1615,24 +1495,19 @@ class PipelineBuildDao { projectId: String, pipelineId: String, debugVersion: Int?, - type: HistorySearchType, - materialAlias: List? = null, - materialBranch: String? = null, - triggerAlias: List? = null, - triggerBranch: String? = null + type: HistorySearchType ): Collection { return if (debugVersion == null) { with(T_PIPELINE_BUILD_HISTORY) { val where = dslContext.selectFrom(this) .where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId))) - makeSearchOptionsCondition( - where = where, - type = type, - materialAlias = materialAlias, - materialBranch = materialBranch, - triggerAlias = triggerAlias, - triggerBranch = triggerBranch - ) + when (type) { + HistorySearchType.MATERIAL -> + where.and(MATERIAL.isNotNull) + + HistorySearchType.TRIGGER -> + where.and(WEBHOOK_INFO.isNotNull) + } where.orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) .fetch(mapper) } @@ -1641,14 +1516,13 @@ class PipelineBuildDao { val where = dslContext.selectFrom(this) .where(PIPELINE_ID.eq(pipelineId).and(PROJECT_ID.eq(projectId))) .and(VERSION.eq(debugVersion)) - makeSearchOptionsDebugCondition( - where = where, - type = type, - materialAlias = materialAlias, - materialBranch = materialBranch, - triggerAlias = triggerAlias, - triggerBranch = triggerBranch - ) + when (type) { + HistorySearchType.MATERIAL -> + where.and(MATERIAL.isNotNull) + + HistorySearchType.TRIGGER -> + where.and(WEBHOOK_INFO.isNotNull) + } where.orderBy(BUILD_NUM.desc()).limit(DEFAULT_PAGE_SIZE) .fetch(debugMapper) } diff --git a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt index 0d6c0cd26f1..00cbc472dc8 100644 --- a/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt +++ b/src/backend/ci/core/process/biz-base/src/main/kotlin/com/tencent/devops/process/engine/service/PipelineRuntimeService.kt @@ -436,8 +436,7 @@ class PipelineRuntimeService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, debugVersion = debugVersion, - type = type, - materialAlias = search?.let { listOf(it) } + type = type ) val materialObjList = mutableListOf() history.forEach { @@ -456,8 +455,7 @@ class PipelineRuntimeService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, debugVersion = debugVersion, - type = type, - triggerAlias = search?.let { listOf(it) } + type = type ) history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookAliasName.isNullOrBlank() } .map { it.webhookInfo!!.webhookAliasName!! } @@ -488,9 +486,7 @@ class PipelineRuntimeService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, debugVersion = debugVersion, - type = type, - materialAlias = aliasList, - materialBranch = search + type = type ) val materialObjList = mutableListOf() history.forEach { @@ -520,9 +516,7 @@ class PipelineRuntimeService @Autowired constructor( projectId = projectId, pipelineId = pipelineId, debugVersion = debugVersion, - type = type, - triggerAlias = aliasList, - triggerBranch = search + type = type ) history.filter { it.webhookInfo != null && !it.webhookInfo!!.webhookBranch.isNullOrBlank() } .map { it.webhookInfo!!.webhookBranch!! }.distinct()