Skip to content

Commit

Permalink
feat: 清理节点接口改为判断lastModifiedDate #1463 (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacYL authored Nov 28, 2023
1 parent 6f48172 commit 3fb6df7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 8 deletions.
8 changes: 4 additions & 4 deletions docs/apidoc/node/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,16 @@
| packages | Int | 节点数量 | node count |


## 清理创建时间早于{date}的文件节点
## 清理最后修改时间早于{date}的文件节点

- API: DELETE /repository/api/node/clean/{projectId}/{repoName}?date=yyyy-MM-dd'T'HH:mm:ss.SSSXXX

- API 名称: delete_node_created_before_date
- API 名称: delete_node_last_modified_before_date

- 功能说明:

- 中文:清理创建时间早于{date}的文件节点
- English:delete node created before date
- 中文:清理最后修改时间早于{date}的文件节点
- English:delete node last modified before date

- 请求体
此接口请求体为空
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.tencent.bkrepo.repository.pojo.node.NodeInfo
import com.tencent.bkrepo.repository.pojo.node.NodeListOption
import com.tencent.bkrepo.repository.pojo.node.NodeRestoreResult
import com.tencent.bkrepo.repository.pojo.node.NodeSizeInfo
import com.tencent.bkrepo.repository.pojo.node.service.NodeCleanRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeCreateRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeDeleteRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeMoveCopyRequest
Expand Down Expand Up @@ -204,4 +205,8 @@ interface NodeClient {
): Response<NodeDetail?>



@ApiOperation("清理最后修改时间早于{date}的文件节点")
@DeleteMapping("/clean")
fun cleanNodes(@RequestBody nodeCleanRequest: NodeCleanRequest): Response<NodeDeleteResult>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available.
*
* Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
*
* BK-CI 蓝鲸持续集成平台 is licensed under the MIT license.
*
* A copy of the MIT License is included in this file.
*
*
* Terms of the MIT License:
* ---------------------------------------------------
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
* the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.tencent.bkrepo.repository.pojo.node.service

import com.tencent.bkrepo.repository.pojo.ServiceRequest
import io.swagger.annotations.ApiModelProperty
import java.time.LocalDateTime

data class NodeCleanRequest(
@ApiModelProperty("所属项目", required = true)
val projectId: String,
@ApiModelProperty("仓库名称", required = true)
val repoName: String,
@ApiModelProperty("清理目录", required = true)
val path: String,
@ApiModelProperty("时间条件", required = true)
val date: LocalDateTime,
@ApiModelProperty("操作用户", required = true)
override val operator: String
): ServiceRequest
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.tencent.bkrepo.repository.pojo.node.NodeInfo
import com.tencent.bkrepo.repository.pojo.node.NodeListOption
import com.tencent.bkrepo.repository.pojo.node.NodeRestoreResult
import com.tencent.bkrepo.repository.pojo.node.NodeSizeInfo
import com.tencent.bkrepo.repository.pojo.node.service.NodeCleanRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeCreateRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeDeleteRequest
import com.tencent.bkrepo.repository.pojo.node.service.NodeMoveCopyRequest
Expand Down Expand Up @@ -184,4 +185,14 @@ class NodeController(
): Response<NodeDetail?> {
return ResponseBuilder.success(nodeService.getDeletedNodeDetailBySha256(projectId, repoName, sha256))
}

override fun cleanNodes(nodeCleanRequest: NodeCleanRequest): Response<NodeDeleteResult> {
return ResponseBuilder.success(nodeService.deleteBeforeDate(
projectId = nodeCleanRequest.projectId,
repoName = nodeCleanRequest.repoName,
path = nodeCleanRequest.path,
date = nodeCleanRequest.date,
operator = nodeCleanRequest.operator
))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ 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 deleteNodeCreatedBeforeDate(
fun deleteNodeLastModifiedBeforeDate(
@RequestAttribute userId: String,
@ArtifactPathVariable artifactInfo: ArtifactInfo,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) date: LocalDateTime
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 @@ -161,7 +161,7 @@ open class NodeDeleteSupport(
): NodeDeleteResult {
val option = NodeListOption(includeFolder = false, deep = true)
val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, path, option)
.and(TNode::createdDate).lt(date)
.and(TNode::lastModifiedDate).lt(date)
val query = Query(criteria)
return delete(query, operator, criteria, projectId, repoName)
}
Expand Down

0 comments on commit 3fb6df7

Please sign in to comment.