Skip to content

Commit

Permalink
feat:新建/编辑流水线时支持调试流水线 #8164 修复构建历史区分源材料分支和触发分支搜索
Browse files Browse the repository at this point in the history
1. 构建历史支持源材料和触发材料搜索
2. 触发分支和源材料分支支持下来搜索
使用服务内存搜索代替mysql搜索
  • Loading branch information
mingshewhe committed Aug 5, 2024
1 parent bca3ec2 commit 628202e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1290,126 +1290,6 @@ class PipelineBuildDao {
}
}

private fun TPipelineBuildHistory.makeSearchOptionsCondition(
where: SelectConditionStep<*>,
type: HistorySearchType,
materialAlias: List<String>? = null,
materialBranch: String? = null,
triggerAlias: List<String>? = 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<String>? = null,
materialBranch: String? = null,
triggerAlias: List<String>? = 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<String>?,
Expand Down Expand Up @@ -1615,24 +1495,19 @@ class PipelineBuildDao {
projectId: String,
pipelineId: String,
debugVersion: Int?,
type: HistorySearchType,
materialAlias: List<String>? = null,
materialBranch: String? = null,
triggerAlias: List<String>? = null,
triggerBranch: String? = null
type: HistorySearchType
): Collection<BuildInfo> {
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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PipelineBuildMaterial>()
history.forEach {
Expand All @@ -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!! }
Expand Down Expand Up @@ -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<PipelineBuildMaterial>()
history.forEach {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 628202e

Please sign in to comment.