From d9833dc0e187fc37cff5b08d7944a967c6b6e594 Mon Sep 17 00:00:00 2001 From: zacYL <100330102+zacYL@users.noreply.github.com> Date: Thu, 9 Nov 2023 10:55:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=8A=82=E7=82=B9=E6=B8=85=E7=90=86?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=94=AF=E6=8C=81=E6=8C=87=E5=AE=9A=E6=B8=85?= =?UTF-8?q?=E7=90=86=E6=8C=87=E5=AE=9A=E7=9B=AE=E5=BD=95=20#1405=20(#1408)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 节点清理节点支持指定清理指定目录 #1405 * feat: 代码格式调整 #1405 --- .../bkrepo/repository/controller/user/UserNodeController.kt | 5 ++++- .../bkrepo/repository/service/node/NodeDeleteOperation.kt | 5 ++++- .../repository/service/node/impl/NodeDeleteSupport.kt | 5 +++-- .../bkrepo/repository/service/node/impl/NodeServiceImpl.kt | 5 +++-- .../node/impl/center/CommitEdgeCenterNodeDeleteSupport.kt | 5 +++-- .../node/impl/center/CommitEdgeCenterNodeServiceImpl.kt | 6 ++++-- .../service/node/impl/edge/EdgeNodeServiceImpl.kt | 5 +++-- 7 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserNodeController.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserNodeController.kt index 42c67689d5..b6c3f5c154 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserNodeController.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/controller/user/UserNodeController.kt @@ -190,7 +190,10 @@ class UserNodeController( @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) date: LocalDateTime ): Response { return ResponseBuilder.success( - nodeService.deleteBeforeDate(artifactInfo.projectId, artifactInfo.repoName, date, userId) + nodeService.deleteBeforeDate( + artifactInfo.projectId, artifactInfo.repoName, + date, userId, artifactInfo.getArtifactFullPath() + ) ) } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/NodeDeleteOperation.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/NodeDeleteOperation.kt index c3731219d6..2383d62ca7 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/NodeDeleteOperation.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/NodeDeleteOperation.kt @@ -69,5 +69,8 @@ interface NodeDeleteOperation { /** * 根据创建时间删除[date]之前的历史数据 */ - fun deleteBeforeDate(projectId: String, repoName: String, date: LocalDateTime, operator: String): NodeDeleteResult + fun deleteBeforeDate( + projectId: String, repoName: String, + date: LocalDateTime, operator: String, path: String + ): NodeDeleteResult } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeDeleteSupport.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeDeleteSupport.kt index 176e8945b9..36a0a600aa 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeDeleteSupport.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeDeleteSupport.kt @@ -156,10 +156,11 @@ open class NodeDeleteSupport( projectId: String, repoName: String, date: LocalDateTime, - operator: String + operator: String, + path: String ): NodeDeleteResult { val option = NodeListOption(includeFolder = false, deep = true) - val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, PathUtils.ROOT, option) + val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, path, option) .and(TNode::createdDate).lt(date) val query = Query(criteria) return delete(query, operator, criteria, projectId, repoName) diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeServiceImpl.kt index 1f3fb9ac84..07aee69c3c 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeServiceImpl.kt @@ -125,9 +125,10 @@ class NodeServiceImpl( projectId: String, repoName: String, date: LocalDateTime, - operator: String + operator: String, + path: String ): NodeDeleteResult { - return NodeDeleteSupport(this).deleteBeforeDate(projectId, repoName, date, operator) + return NodeDeleteSupport(this).deleteBeforeDate(projectId, repoName, date, operator, path) } @Transactional(rollbackFor = [Throwable::class]) diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeDeleteSupport.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeDeleteSupport.kt index de48a96519..f776c712ce 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeDeleteSupport.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeDeleteSupport.kt @@ -99,12 +99,13 @@ class CommitEdgeCenterNodeDeleteSupport( projectId: String, repoName: String, date: LocalDateTime, - operator: String + operator: String, + path: String ): NodeDeleteResult { var deletedSize = 0L var deletedNum = 0L val option = NodeListOption(includeFolder = false, deep = true) - val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, PathUtils.ROOT, option) + val criteria = NodeQueryHelper.nodeListCriteria(projectId, repoName, path, option) .and(TNode::createdDate).lt(date) val pageSize = 1 var queryCount: Int diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeServiceImpl.kt index bd11d120bb..976b5a5d41 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeServiceImpl.kt @@ -208,13 +208,15 @@ class CommitEdgeCenterNodeServiceImpl( projectId: String, repoName: String, date: LocalDateTime, - operator: String + operator: String, + path: String ): NodeDeleteResult { return CommitEdgeCenterNodeDeleteSupport(this, clusterProperties).deleteBeforeDate( projectId, repoName, date, - operator + operator, + path ) } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeServiceImpl.kt index 34479b7496..d8a46c4464 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/edge/EdgeNodeServiceImpl.kt @@ -135,9 +135,10 @@ class EdgeNodeServiceImpl( projectId: String, repoName: String, date: LocalDateTime, - operator: String + operator: String, + path: String ): NodeDeleteResult { - return NodeDeleteSupport(this).deleteBeforeDate(projectId, repoName, date, operator) + return NodeDeleteSupport(this).deleteBeforeDate(projectId, repoName, date, operator, path) } @Transactional(rollbackFor = [Throwable::class])