Skip to content

Commit

Permalink
feat: 根据最后访问时间删除历史节点 #1913
Browse files Browse the repository at this point in the history
* feat: 根据最后访问时间删除历史节点 #1913

* feat: 根据最后访问时间删除历史节点 #1913

* feat: 根据最后访问时间删除历史节点 #1913

* feat: 参数传递 #1913
  • Loading branch information
zacYL authored Mar 21, 2024
1 parent a83fd0f commit 2a8d4af
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ interface NodeClient {
@PutMapping("/uncompress/")
fun uncompressedNode(@RequestBody nodeUnCompressedRequest: NodeUnCompressedRequest): Response<Void>

@ApiOperation("清理最后修改时间早于{date}的文件节点")
@ApiOperation("清理最后访问时间早于{date}的文件节点")
@DeleteMapping("/clean")
fun cleanNodes(@RequestBody nodeCleanRequest: NodeCleanRequest): Response<NodeDeleteResult>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class UserNodeController(
return ResponseBuilder.success(nodeService.countDeleteNodes(nodesDeleteRequest))
}

@ApiOperation("清理最后修改时间早于{date}的文件节点")
@ApiOperation("清理最后访问时间早于{date}的文件节点")
@Permission(type = ResourceType.NODE, action = PermissionAction.DELETE)
@DeleteMapping("/clean/$DEFAULT_MAPPING_URI")
fun deleteNodeLastModifiedBeforeDate(
Expand Down Expand Up @@ -345,7 +345,7 @@ class UserNodeController(
@ArtifactPathVariable artifactInfo: ArtifactInfo,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) date: LocalDateTime
): Response<NodeSizeInfo> {
val nodeSizeInfo = nodeService.computeSize(artifactInfo,false, date)
val nodeSizeInfo = nodeService.computeSize(artifactInfo,false, date, true)
return ResponseBuilder.success(nodeSizeInfo)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface NodeDeleteOperation {
fun deleteByPaths(projectId: String, repoName: String, fullPaths: List<String>, operator: String): NodeDeleteResult

/**
* 根据最后修改时间删除[date]之前的历史数据
* 根据最后访问时间删除[date]之前的历史数据
*/
fun deleteBeforeDate(
projectId: String, repoName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ interface NodeStatsOperation {
*/
fun computeSize(artifact: ArtifactInfo,
estimated: Boolean = false,
before: LocalDateTime = LocalDateTime.now()
before: LocalDateTime = LocalDateTime.now(),
cleanUp: Boolean = false
): NodeSizeInfo

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ open class NodeDeleteSupport(
path: String
): NodeDeleteResult {
val option = NodeListOption(includeFolder = false, deep = true)
val timeCriteria = Criteria().orOperator(
Criteria().and(TNode::lastAccessDate).lt(date).and(TNode::lastModifiedDate).lt(date),
Criteria().and(TNode::lastAccessDate).`is`(null).and(TNode::lastModifiedDate).lt(date),
)
val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, path, option)
.and(TNode::lastModifiedDate).lt(date)
.andOperator(timeCriteria)
val query = Query(criteria)
val nodeDeleteResult = delete(query, operator, criteria, projectId, repoName)
publishEvent(buildNodeCleanEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ class NodeServiceImpl(
routerControllerProperties
) {

override fun computeSize(artifact: ArtifactInfo, estimated: Boolean, before: LocalDateTime): NodeSizeInfo {
return NodeStatsSupport(this).computeSize(artifact, estimated, before)
override fun computeSize(
artifact: ArtifactInfo, estimated: Boolean, before: LocalDateTime, cleanUp: Boolean
): NodeSizeInfo {
return NodeStatsSupport(this).computeSize(artifact, estimated, before, cleanUp)
}

override fun aggregateComputeSize(criteria: Criteria): Long {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ open class NodeStatsSupport(

private val nodeDao: NodeDao = nodeBaseService.nodeDao

override fun computeSize(artifact: ArtifactInfo, estimated: Boolean, before: LocalDateTime): NodeSizeInfo {
override fun computeSize(
artifact: ArtifactInfo,
estimated: Boolean,
before: LocalDateTime,
cleanUp: Boolean
): NodeSizeInfo {
val projectId = artifact.projectId
val repoName = artifact.repoName
val fullPath = artifact.getArtifactFullPath()
Expand All @@ -72,13 +77,21 @@ open class NodeStatsSupport(
return computeEstimatedSize(node)
}
val listOption = NodeListOption(includeFolder = true, deep = true)
val timeCriteria = if (cleanUp) {
Criteria().orOperator(
Criteria().and(TNode::lastAccessDate).lt(before).and(TNode::lastModifiedDate).lt(before),
Criteria().and(TNode::lastAccessDate).`is`(null).and(TNode::lastModifiedDate).lt(before),
)
} else {
Criteria().and(TNode::lastModifiedDate).lt(before)
}
val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, node.fullPath, listOption)
.and(TNode::lastModifiedDate).lt(before)
.andOperator(timeCriteria)
val count = nodeDao.count(Query(criteria))
val listOptionWithOutFolder = NodeListOption(includeFolder = false, deep = true)
val criteriaWithOutFolder = NodeQueryHelper.nodeListCriteria(
projectId, repoName, node.fullPath, listOptionWithOutFolder
).and(TNode::lastModifiedDate).lt(before)
).andOperator(timeCriteria)
val countWithOutFolder = nodeDao.count(Query(criteriaWithOutFolder))
val size = aggregateComputeSize(criteriaWithOutFolder)
nodeDao.setSizeAndNodeNumOfFolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ class EdgeNodeServiceImpl(
routerControllerProperties,
clusterProperties,
) {
override fun computeSize(artifact: ArtifactInfo, estimated: Boolean, before: LocalDateTime): NodeSizeInfo {
return NodeStatsSupport(this).computeSize(artifact, estimated, before)
override fun computeSize(
artifact: ArtifactInfo, estimated: Boolean, before: LocalDateTime, cleanUp: Boolean
): NodeSizeInfo {
return NodeStatsSupport(this).computeSize(artifact, estimated, before, cleanUp)
}

override fun aggregateComputeSize(criteria: Criteria): Long {
Expand Down

0 comments on commit 2a8d4af

Please sign in to comment.