Skip to content

Commit

Permalink
feat: search逻辑调整TencentBlueKing#2316
Browse files Browse the repository at this point in the history
  • Loading branch information
zacYL committed Sep 20, 2024
1 parent 07262dc commit dd45d4f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.tencent.bkrepo.common.security.permission.Permission
import com.tencent.bkrepo.conan.pojo.artifact.ConanArtifactInfo
import com.tencent.bkrepo.conan.pojo.artifact.ConanArtifactInfo.Companion.PACKAGE_SEARCH_V1
import com.tencent.bkrepo.conan.pojo.artifact.ConanArtifactInfo.Companion.PACKAGE_SEARCH_V2
import com.tencent.bkrepo.conan.pojo.artifact.ConanArtifactInfo.Companion.REVISION_SEARCH_V2
import com.tencent.bkrepo.conan.pojo.artifact.ConanArtifactInfo.Companion.SEARCH_V1
import com.tencent.bkrepo.conan.pojo.artifact.ConanArtifactInfo.Companion.SEARCH_V2
import com.tencent.bkrepo.conan.service.ConanSearchService
Expand Down Expand Up @@ -62,7 +63,7 @@ class ConanSearchController(
return ConanCommonController.buildResponse(conanSearchService.search(projectId, repoName, q, ignoreCase))
}

@GetMapping(PACKAGE_SEARCH_V1, PACKAGE_SEARCH_V2)
@GetMapping(PACKAGE_SEARCH_V1, PACKAGE_SEARCH_V2, REVISION_SEARCH_V2)
@Permission(type = ResourceType.REPO, action = PermissionAction.READ)
fun searchPackages(
@ArtifactPathVariable conanArtifactInfo: ConanArtifactInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class ConanArtifactInfo(
// search
const val SEARCH_V2 = "/{projectId}/{repoName}/v2/conans/search"

const val REVISION_SEARCH_V2 = "/{projectId}/{repoName}/v2/conans/" +
"{name}/{version}/{username}/{channel}/revisions/{revision}/search"
// package search
const val PACKAGE_SEARCH_V2 = "/{projectId}/{repoName}/v2/conans/" +
"{name}/{version}/{username}/{channel}/search"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,7 @@ class CommonService(
repoName: String,
revPath: String,
): List<String> {
nodeClient.getNodeDetail(projectId, repoName, revPath).data
?: throw NodeNotFoundException(revPath)
nodeClient.getNodeDetail(projectId, repoName, revPath).data ?: return emptyList()
return nodeClient.listNode(projectId, repoName, revPath, includeFolder = true, deep = false).data!!.map {
it.name
}
Expand Down Expand Up @@ -541,37 +540,16 @@ class CommonService(
conanFileReference: ConanFileReference
): Map<String, ConanInfo> {
val result = mutableMapOf<String, ConanInfo>()
val revPath = getRecipeRevisionsFile(conanFileReference)
val refStr = buildReference(conanFileReference)
val indexJson = getRevisionsList(
projectId = projectId,
repoName = repoName,
revPath = revPath,
refStr = refStr
)
val revisions = indexJson.revisions.ifEmpty {
// val revisionV1Path = joinString("/$revPath", DEFAULT_REVISION_V1)
// nodeClient.getNodeDetail(projectId, repoName, revisionV1Path).data ?: return emptyMap()
// listOf(RevisionInfo(DEFAULT_REVISION_V1, convertToUtcTime(LocalDateTime.now())))
emptyList()
}

revisions.forEach {
val conf = conanFileReference.copy(revision = it.revision)
val tempRevPath = getPackageRevisionsFile(conf)
val packageIds = getPackageIdList(projectId, repoName, tempRevPath)
packageIds.forEach { packageId ->
val packageReference = PackageReference(conf, packageId)
val prevPath = getPackageRevisionsFile(packageReference)
val prefStr = buildPackageReference(packageReference)
val packageIndexJson = getRevisionsList(
projectId = projectId,
repoName = repoName,
revPath = prevPath,
refStr = prefStr
)
val lastRevision = packageIndexJson.revisions.first()
val path = getPackageConanInfoFile(packageReference.copy(revision = lastRevision.revision))
val tempRevPath = getPackageRevisionsFile(conanFileReference)
val packageIds = getPackageIdList(projectId, repoName, tempRevPath)
packageIds.forEach { packageId ->
val packageReference = PackageReference(conanFileReference, packageId)
getLastPackageRevision(
projectId = projectId,
repoName = repoName,
packageReference = packageReference,
)?.let {
val path = getPackageConanInfoFile(packageReference.copy(revision = it.revision))
result[packageId] = getContentOfConanInfoFile(projectId, repoName, path)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@ package com.tencent.bkrepo.conan.service.impl

import com.tencent.bkrepo.common.api.util.readJsonString
import com.tencent.bkrepo.common.api.util.toJsonString
import com.tencent.bkrepo.common.artifact.exception.NodeNotFoundException
import com.tencent.bkrepo.conan.constant.CONAN_INFOS
import com.tencent.bkrepo.conan.constant.ConanMessageCode
import com.tencent.bkrepo.conan.exception.ConanSearchNotFoundException
import com.tencent.bkrepo.conan.pojo.ConanFileReference
import com.tencent.bkrepo.conan.pojo.ConanInfo
import com.tencent.bkrepo.conan.pojo.ConanSearchResult
import com.tencent.bkrepo.conan.pojo.artifact.ConanArtifactInfo
import com.tencent.bkrepo.conan.service.ConanSearchService
import com.tencent.bkrepo.conan.utils.ConanArtifactInfoUtil.convertToConanFileReference
import com.tencent.bkrepo.conan.utils.PathUtils.buildConanFileName
import com.tencent.bkrepo.conan.utils.PathUtils.buildReference
import com.tencent.bkrepo.conan.utils.PathUtils.buildPackagePath
import com.tencent.bkrepo.repository.api.PackageClient
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
Expand All @@ -50,6 +47,7 @@ class ConanSearchServiceImpl : ConanSearchService {

@Autowired
lateinit var packageClient: PackageClient

@Autowired
lateinit var commonService: CommonService

Expand All @@ -76,18 +74,15 @@ class ConanSearchServiceImpl : ConanSearchService {

override fun searchPackages(pattern: String?, conanArtifactInfo: ConanArtifactInfo): Map<String, ConanInfo> {
with(conanArtifactInfo) {
val conanFileReference = convertToConanFileReference(conanArtifactInfo)
val result = try {
commonService.getPackageConanInfo(projectId, repoName, conanFileReference)
} catch (ignore: NodeNotFoundException) {
emptyMap()
}
if (result.isEmpty()) {
throw ConanSearchNotFoundException(
ConanMessageCode.CONAN_SEARCH_NOT_FOUND, buildReference(conanFileReference), getRepoIdentify()
)
val realRevision = if (revision.isNullOrEmpty()) {
val conanFileReference = convertToConanFileReference(conanArtifactInfo)
commonService.getNodeDetail(projectId, repoName, buildPackagePath(conanFileReference))
commonService.getLastRevision(projectId, repoName, conanFileReference)?.revision ?: return emptyMap()
} else {
revision
}
return result
val conanFileReference = convertToConanFileReference(conanArtifactInfo, realRevision)
return commonService.getPackageConanInfo(projectId, repoName, conanFileReference)
}
}

Expand Down

0 comments on commit dd45d4f

Please sign in to comment.