Skip to content

Commit

Permalink
feat: 新增节点下非目录节点数量字段 #1012
Browse files Browse the repository at this point in the history
  • Loading branch information
zacYL committed Aug 24, 2023
1 parent 242bf5b commit c12dbf8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ import io.swagger.annotations.ApiModelProperty
*/
@ApiModel("节点大小信息")
data class NodeSizeInfo(
@ApiModelProperty("子节点数量, 不包含文件夹")
@ApiModelProperty("子节点数量, 包含文件夹")
val subNodeCount: Long = 0,
@ApiModelProperty("子节点数量, 不包含文件夹")
val subNodeWithoutFolderCount: Long = 0,
@ApiModelProperty("文件大小总和")
val size: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ abstract class NodeBaseService(
size = if (folder) 0 else size ?: 0,
sha256 = if (folder) null else sha256,
md5 = if (folder) null else md5,
nodeNum = if (folder) null else 1,
nodeNum = null,
metadata = MetadataUtils.compatibleConvertAndCheck(metadata, nodeMetadata),
createdBy = createdBy ?: operator,
createdDate = createdDate ?: LocalDateTime.now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,25 @@ open class NodeStatsSupport(
?: throw ErrorCodeException(ArtifactMessageCode.NODE_NOT_FOUND, fullPath)
// 节点为文件直接返回
if (!node.folder) {
return NodeSizeInfo(subNodeCount = 0, size = node.size)
return NodeSizeInfo(subNodeCount = 0, subNodeWithoutFolderCount = 0, size = node.size)
}
val listOption = NodeListOption(includeFolder = false, deep = true)
val listOption = NodeListOption(includeFolder = true, deep = true)
val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, node.fullPath, listOption)
val count = nodeDao.count(Query(criteria))
val size = aggregateComputeSize(criteria)
val listOptionWithOutFolder = NodeListOption(includeFolder = false, deep = true)
val criteriaWithOutFolder = NodeQueryHelper.nodeListCriteria(
projectId, repoName, node.fullPath, listOptionWithOutFolder
)
val countWithOutFolder = nodeDao.count(Query(criteriaWithOutFolder))
val size = aggregateComputeSize(criteriaWithOutFolder)
nodeDao.setSizeAndNodeNumOfFolder(
projectId = projectId,
repoName = repoName,
fullPath = fullPath,
size = size,
nodeNum = count
nodeNum = countWithOutFolder
)
return NodeSizeInfo(subNodeCount = count, size = size)
return NodeSizeInfo(subNodeCount = count, subNodeWithoutFolderCount = countWithOutFolder, size = size)
}

override fun countFileNode(artifact: ArtifactInfo): Long {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ class NodeServiceTest @Autowired constructor(

val pathSizeInfo = nodeService.computeSize(node("/a/b"))

assertEquals(40, pathSizeInfo.subNodeCount)
assertEquals(42, pathSizeInfo.subNodeCount)
assertEquals(40, pathSizeInfo.subNodeWithoutFolderCount)
assertEquals(40, pathSizeInfo.size)
}

Expand All @@ -347,7 +348,8 @@ class NodeServiceTest @Autowired constructor(

val pathSizeInfo = nodeService.computeSize(node("/"))

assertEquals(40, pathSizeInfo.subNodeCount)
assertEquals(42, pathSizeInfo.subNodeCount)
assertEquals(40, pathSizeInfo.subNodeWithoutFolderCount)
assertEquals(40, pathSizeInfo.size)
}

Expand Down

0 comments on commit c12dbf8

Please sign in to comment.