Skip to content

Commit

Permalink
pref:优化研发商店组件下架逻辑 TencentBlueKing#11308
Browse files Browse the repository at this point in the history
  • Loading branch information
carlyin0801 committed Dec 11, 2024
1 parent 4722043 commit d2beedc
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ abstract class AtomBaseDao {
}
}

fun getMaxVersionAtomByCode(dslContext: DSLContext, atomCode: String): TAtomRecord? {
fun getMaxVersionAtomByCode(
dslContext: DSLContext,
atomCode: String,
atomStatus: AtomStatusEnum? = null
): TAtomRecord? {
return with(TAtom.T_ATOM) {
val conditions = mutableListOf<Condition>()
conditions.add(ATOM_CODE.eq(atomCode))
if (atomStatus != null) {
conditions.add(ATOM_STATUS.eq(atomStatus.status.toByte()))
}
dslContext.selectFrom(this)
.where(ATOM_CODE.eq(atomCode))
.where(conditions)
.orderBy(
JooqUtils.subStr(
str = VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ class MarketAtomDao : AtomBaseDao() {
recommendFlag: Boolean?,
qualityFlag: Boolean?
) {
if (labelCodeList != null && labelCodeList.isNotEmpty()) {
if (!labelCodeList.isNullOrEmpty()) {
val tLabel = TLabel.T_LABEL
val labelIdList = dslContext.select(tLabel.ID)
.from(tLabel)
.where(tLabel.LABEL_CODE.`in`(labelCodeList)).and(tLabel.TYPE.eq(storeType))
.fetch().map { it["ID"] as String }
.fetch().map { it[tLabel.ID] as String }
val talr = TAtomLabelRel.T_ATOM_LABEL_REL
baseStep.leftJoin(talr).on(ta.ID.eq(talr.ATOM_ID))
conditions.add(talr.LABEL_ID.`in`(labelIdList))
Expand All @@ -257,10 +257,12 @@ class MarketAtomDao : AtomBaseDao() {
tas.DOWNLOADS.`as`(MarketAtomSortTypeEnum.DOWNLOAD_COUNT.name),
tas.RECENT_EXECUTE_NUM.`as`(MarketAtomSortTypeEnum.RECENT_EXECUTE_NUM.name),
tas.SCORE_AVERAGE
).from(tas).asTable("t")
baseStep.leftJoin(t).on(ta.ATOM_CODE.eq(t.field("STORE_CODE", String::class.java)))
conditions.add(t.field("SCORE_AVERAGE", BigDecimal::class.java)!!.ge(BigDecimal.valueOf(score.toLong())))
conditions.add(t.field("STORE_TYPE", Byte::class.java)!!.eq(storeType))
).from(tas)
baseStep.leftJoin(t).on(ta.ATOM_CODE.eq(t.field(tas.STORE_CODE.name, String::class.java)))
conditions.add(
t.field(tas.SCORE_AVERAGE.name, BigDecimal::class.java)!!.ge(BigDecimal.valueOf(score.toLong()))
)
conditions.add(t.field(tas.STORE_TYPE.name, Byte::class.java)!!.eq(storeType))
}
if (null != yamlFlag) {
conditions.add(taf.YAML_FLAG.eq(yamlFlag))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,7 @@ abstract class AtomReleaseServiceImpl @Autowired constructor() : AtomReleaseServ
atomCode = atomCode,
atomId = atomRecord.id,
userId = userId,
reason = reason,
version = version
reason = reason
)
}
}
Expand All @@ -1233,55 +1232,57 @@ abstract class AtomReleaseServiceImpl @Autowired constructor() : AtomReleaseServ
atomCode: String,
atomId: String,
userId: String,
reason: String?,
version: String
reason: String?
) {
// 查找插件最近二个已经发布的版本
val releaseAtomRecords = marketAtomDao.getReleaseAtomsByCode(context, atomCode, 2)
if (null != releaseAtomRecords && releaseAtomRecords.size > 0) {
marketAtomDao.updateAtomInfoById(
dslContext = context,
atomId = atomId,
userId = userId,
updateAtomInfo = UpdateAtomInfo(
atomStatus = AtomStatusEnum.UNDERCARRIAGED.status.toByte(),
atomStatusMsg = reason,
latestFlag = false
)
)
redisOperation.delete(StoreUtils.getStoreRunInfoKey(StoreTypeEnum.ATOM.name, atomCode))
// 获取插件已发布版本数量
val releaseCount = marketAtomDao.countReleaseAtomByCode(context, atomCode)
val tmpAtomId = if (releaseCount > 0) {
// 获取已发布最大版本的插件记录
val maxReleaseVersionRecord = marketAtomDao.getMaxVersionAtomByCode(
dslContext = context,
atomCode = atomCode,
atomStatus = AtomStatusEnum.RELEASED
)
maxReleaseVersionRecord?.let {
// 处理插件缓存(保证用户用到当前大版本中已发布的版本)
marketAtomCommonService.handleAtomCache(
atomId = maxReleaseVersionRecord.id,
atomCode = atomCode,
version = maxReleaseVersionRecord.version,
releaseFlag = false
)
}
maxReleaseVersionRecord?.id
} else {
// 获取已下架最大版本的插件记录
val maxUndercarriagedVersionRecord = marketAtomDao.getMaxVersionAtomByCode(
dslContext = context,
atomCode = atomCode,
atomStatus = AtomStatusEnum.UNDERCARRIAGED
)
maxUndercarriagedVersionRecord?.id
}
if (null != tmpAtomId) {
marketAtomDao.cleanLatestFlag(context, atomCode)
marketAtomDao.updateAtomInfoById(
dslContext = context,
atomId = atomId,
atomId = tmpAtomId,
userId = userId,
updateAtomInfo = UpdateAtomInfo(
atomStatus = AtomStatusEnum.UNDERCARRIAGED.status.toByte(),
atomStatusMsg = reason,
latestFlag = false
latestFlag = true
)
)
redisOperation.delete(StoreUtils.getStoreRunInfoKey(StoreTypeEnum.ATOM.name, atomCode))
val newestReleaseAtomRecord = releaseAtomRecords[0]
if (newestReleaseAtomRecord.id == atomId) {
var tmpAtomId: String? = null
if (releaseAtomRecords.size == 1) {
val newestUndercarriagedAtom =
marketAtomDao.getNewestUndercarriagedAtomsByCode(context, atomCode)
if (null != newestUndercarriagedAtom) {
tmpAtomId = newestUndercarriagedAtom.id
}
} else {
// 把前一个发布的版本的latestFlag置为true
val tmpAtomRecord = releaseAtomRecords[1]
tmpAtomId = tmpAtomRecord.id
// 处理插件缓存(保证用户用到当前大版本中已发布的版本)
marketAtomCommonService.handleAtomCache(
atomId = tmpAtomId,
atomCode = atomCode,
version = tmpAtomRecord.version,
releaseFlag = false
)
}
if (null != tmpAtomId) {
marketAtomDao.updateAtomInfoById(
dslContext = context,
atomId = tmpAtomId,
userId = userId,
updateAtomInfo = UpdateAtomInfo(
latestFlag = true
)
)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,18 @@ class StoreBaseQueryDao {
fun getMaxVersionComponentByCode(
dslContext: DSLContext,
storeCode: String,
storeType: StoreTypeEnum
storeType: StoreTypeEnum,
status: StoreStatusEnum? = null
): TStoreBaseRecord? {
return with(TStoreBase.T_STORE_BASE) {
val conditions = mutableListOf<Condition>()
conditions.add(STORE_TYPE.eq(storeType.type.toByte()))
conditions.add(STORE_CODE.eq(storeCode))
if (status != null) {
conditions.add(STATUS.eq(status.name))
}
dslContext.selectFrom(this)
.where(STORE_CODE.eq(storeCode).and(STORE_TYPE.eq(storeType.type.toByte())))
.where(conditions)
.orderBy(
JooqUtils.subStr(
str = VERSION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import com.tencent.devops.store.common.service.StoreReleaseService
import com.tencent.devops.store.common.service.StoreReleaseSpecBusService
import com.tencent.devops.store.common.utils.StoreUtils
import com.tencent.devops.store.constant.StoreMessageCode
import com.tencent.devops.store.pojo.atom.UpdateAtomInfo
import com.tencent.devops.store.pojo.atom.enums.AtomStatusEnum
import com.tencent.devops.store.pojo.common.CLOSE
import com.tencent.devops.store.pojo.common.KEY_STORE_ID
import com.tencent.devops.store.pojo.common.enums.AuditTypeEnum
Expand Down Expand Up @@ -443,11 +445,6 @@ class StoreReleaseServiceImpl @Autowired constructor(
val storeId = baseRecord.id
dslContext.transaction { t ->
val context = DSL.using(t)
// 查找插件最近二个已经发布的版本
val releaseRecords = storeBaseQueryDao.getReleaseComponentsByCode(context, storeCode, storeType, 2)
if (releaseRecords.isNullOrEmpty()) {
return@transaction
}
storeBaseManageDao.updateStoreBaseInfo(
dslContext = dslContext,
updateStoreBaseDataPO = UpdateStoreBaseDataPO(
Expand All @@ -458,33 +455,42 @@ class StoreReleaseServiceImpl @Autowired constructor(
modifier = userId
)
)
if (releaseRecords[0].id == storeId) {
var tmpStoreId: String? = null
if (releaseRecords.size == 1) {
val newestUndercarriagedRecord = storeBaseQueryDao.getNewestComponentByCode(
dslContext = context,
storeCode = storeCode,
storeType = storeType,
status = StoreStatusEnum.UNDERCARRIAGED
)
if (null != newestUndercarriagedRecord) {
tmpStoreId = newestUndercarriagedRecord.id
}
} else {
// 把前一个发布的版本的latestFlag置为true
val tmpStoreRecord = releaseRecords[1]
tmpStoreId = tmpStoreRecord.id
}
tmpStoreId?.let {
storeBaseManageDao.updateStoreBaseInfo(
dslContext = dslContext,
updateStoreBaseDataPO = UpdateStoreBaseDataPO(
id = tmpStoreId,
latestFlag = true,
modifier = userId
)
// 获取插件已发布版本数量
val releaseCount = storeBaseQueryDao.countByCondition(
dslContext = context,
storeType = storeType,
storeCode = storeCode,
status = StoreStatusEnum.RELEASED
)
val tmpStoreId = if (releaseCount > 0) {
// 获取已发布最大版本的插件记录
val maxReleaseVersionRecord = storeBaseQueryDao.getMaxVersionComponentByCode(
dslContext = context,
storeType = storeType,
storeCode = storeCode,
status = StoreStatusEnum.RELEASED
)
maxReleaseVersionRecord?.id
} else {
// 获取已下架最大版本的插件记录
val maxUndercarriagedVersionRecord = storeBaseQueryDao.getMaxVersionComponentByCode(
dslContext = context,
storeType = storeType,
storeCode = storeCode,
status = StoreStatusEnum.UNDERCARRIAGED
)
maxUndercarriagedVersionRecord?.id
}
if (null != tmpStoreId) {
storeBaseManageDao.cleanLatestFlag(context, storeCode, storeType)
storeBaseManageDao.updateStoreBaseInfo(
dslContext = context,
updateStoreBaseDataPO = UpdateStoreBaseDataPO(
id = tmpStoreId,
latestFlag = true,
modifier = userId
)
}
)
}
}
}
Expand Down

0 comments on commit d2beedc

Please sign in to comment.