From 65dc8be4b76cd20e88ef0339835e10d5b8a4f2f2 Mon Sep 17 00:00:00 2001 From: ericwu Date: Mon, 18 Sep 2023 16:26:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=9B=AE=E5=BD=95=E5=86=85=E7=9A=84?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E5=B1=82=E8=8A=82=E7=82=B9=E5=8F=91=E7=94=9F?= =?UTF-8?q?=E6=94=B9=E5=8F=98=E6=97=B6,=E6=9B=B4=E6=96=B0=E8=AF=A5?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=9A=84=E6=9C=80=E5=90=8E=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20#756?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metadata/impl/MetadataServiceImpl.kt | 23 ++++- .../CommitEdgeCenterMetadataServiceImpl.kt | 6 +- .../impl/edge/EdgeMetadataServiceImpl.kt | 6 +- .../service/node/impl/NodeBaseService.kt | 91 ++++++++++++++++++- .../service/node/impl/NodeDeleteSupport.kt | 16 +++- .../service/node/impl/NodeMoveCopySupport.kt | 7 ++ .../service/node/impl/NodeRenameSupport.kt | 10 +- .../service/node/impl/NodeRestoreSupport.kt | 10 +- .../CommitEdgeCenterNodeRestoreSupport.kt | 8 +- .../center/CommitEdgeCenterNodeServiceImpl.kt | 9 +- .../bkrepo/repository/util/NodeQueryHelper.kt | 4 +- 11 files changed, 167 insertions(+), 23 deletions(-) diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/MetadataServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/MetadataServiceImpl.kt index 4ccc37cb06..a61837f7bd 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/MetadataServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/MetadataServiceImpl.kt @@ -36,6 +36,7 @@ import com.tencent.bkrepo.common.api.exception.ErrorCodeException import com.tencent.bkrepo.common.api.message.CommonMessageCode import com.tencent.bkrepo.common.artifact.exception.NodeNotFoundException import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode +import com.tencent.bkrepo.common.artifact.path.PathUtils import com.tencent.bkrepo.common.artifact.path.PathUtils.normalizeFullPath import com.tencent.bkrepo.common.artifact.util.ClusterUtils import com.tencent.bkrepo.common.security.exception.PermissionException @@ -48,6 +49,7 @@ import com.tencent.bkrepo.repository.model.TNode import com.tencent.bkrepo.repository.pojo.metadata.MetadataDeleteRequest import com.tencent.bkrepo.repository.pojo.metadata.MetadataSaveRequest import com.tencent.bkrepo.repository.service.metadata.MetadataService +import com.tencent.bkrepo.repository.service.node.impl.NodeBaseService import com.tencent.bkrepo.repository.util.MetadataUtils import com.tencent.bkrepo.repository.util.NodeEventFactory.buildMetadataDeletedEvent import com.tencent.bkrepo.repository.util.NodeEventFactory.buildMetadataSavedEvent @@ -60,6 +62,7 @@ import org.springframework.data.mongodb.core.query.inValues import org.springframework.data.mongodb.core.query.where import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional +import java.time.LocalDateTime /** * 元数据服务实现类 @@ -67,10 +70,12 @@ import org.springframework.transaction.annotation.Transactional @Service @Conditional(DefaultCondition::class) class MetadataServiceImpl( - private val nodeDao: NodeDao, + private val nodeBaseService: NodeBaseService, private val repositoryProperties: RepositoryProperties ) : MetadataService { + private val nodeDao: NodeDao = nodeBaseService.nodeDao + override fun listMetadata(projectId: String, repoName: String, fullPath: String): Map { return MetadataUtils.toMap(nodeDao.findOne(NodeQueryHelper.nodeQuery(projectId, repoName, fullPath))?.metadata) } @@ -94,7 +99,13 @@ class MetadataServiceImpl( checkIfUpdateSystemMetadata(oldMetadata, newMetadata) node.metadata = MetadataUtils.merge(oldMetadata, newMetadata) + val currentTime = LocalDateTime.now() + node.lastModifiedBy = operator + node.lastModifiedDate = currentTime nodeDao.save(node) + // 更新父目录的修改时间 + val parentFullPath = PathUtils.toFullPath(PathUtils.resolveParent(fullPath)) + nodeBaseService.updateModifiedInfo(projectId, repoName, parentFullPath, operator, currentTime) publishEvent(buildMetadataSavedEvent(request)) logger.info("Save metadata[$newMetadata] on node[/$projectId/$repoName$fullPath] success.") } @@ -131,11 +142,17 @@ class MetadataServiceImpl( } } + val currentTime = LocalDateTime.now() val update = Update().pull( TNode::metadata.name, Query.query(where(TMetadata::key).inValues(keyList)) - ) - nodeDao.updateMulti(query, update) + ).set(TNode::lastModifiedDate.name, currentTime).set(TNode::lastModifiedBy.name, operator) + val modifiedCount = nodeDao.updateMulti(query, update).modifiedCount + if (modifiedCount == 1L) { + // 更新父目录的修改时间 + val parentFullPath = PathUtils.toFullPath(PathUtils.resolveParent(fullPath)) + nodeBaseService.updateModifiedInfo(projectId, repoName, parentFullPath, operator, currentTime) + } publishEvent(buildMetadataDeletedEvent(this)) logger.info("Delete metadata[$keyList] on node[/$projectId/$repoName$fullPath] success.") } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/center/CommitEdgeCenterMetadataServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/center/CommitEdgeCenterMetadataServiceImpl.kt index 28ac6a5de8..8da70f7b15 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/center/CommitEdgeCenterMetadataServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/center/CommitEdgeCenterMetadataServiceImpl.kt @@ -29,17 +29,17 @@ package com.tencent.bkrepo.repository.service.metadata.impl.center import com.tencent.bkrepo.common.service.cluster.CommitEdgeCenterCondition import com.tencent.bkrepo.repository.config.RepositoryProperties -import com.tencent.bkrepo.repository.dao.NodeDao import com.tencent.bkrepo.repository.service.metadata.impl.MetadataServiceImpl +import com.tencent.bkrepo.repository.service.node.impl.NodeBaseService import org.springframework.context.annotation.Conditional import org.springframework.stereotype.Service @Service @Conditional(CommitEdgeCenterCondition::class) class CommitEdgeCenterMetadataServiceImpl( - nodeDao: NodeDao, + nodeBaseService: NodeBaseService, repositoryProperties: RepositoryProperties ) : MetadataServiceImpl( - nodeDao, + nodeBaseService, repositoryProperties ) diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/edge/EdgeMetadataServiceImpl.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/edge/EdgeMetadataServiceImpl.kt index afcbc83a06..b39cdfb0d4 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/edge/EdgeMetadataServiceImpl.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/metadata/impl/edge/EdgeMetadataServiceImpl.kt @@ -32,21 +32,21 @@ import com.tencent.bkrepo.common.service.cluster.CommitEdgeEdgeCondition import com.tencent.bkrepo.common.service.feign.FeignClientFactory import com.tencent.bkrepo.repository.api.cluster.ClusterMetadataClient import com.tencent.bkrepo.repository.config.RepositoryProperties -import com.tencent.bkrepo.repository.dao.NodeDao import com.tencent.bkrepo.repository.pojo.metadata.MetadataDeleteRequest import com.tencent.bkrepo.repository.pojo.metadata.MetadataSaveRequest import com.tencent.bkrepo.repository.service.metadata.impl.MetadataServiceImpl +import com.tencent.bkrepo.repository.service.node.impl.NodeBaseService import org.springframework.context.annotation.Conditional import org.springframework.stereotype.Service @Service @Conditional(CommitEdgeEdgeCondition::class) class EdgeMetadataServiceImpl( - nodeDao: NodeDao, + nodeBaseService: NodeBaseService, repositoryProperties: RepositoryProperties, clusterProperties: ClusterProperties ) : MetadataServiceImpl( - nodeDao, + nodeBaseService, repositoryProperties ) { diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeBaseService.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeBaseService.kt index 536a49b659..94f77afd88 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeBaseService.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeBaseService.kt @@ -27,6 +27,10 @@ package com.tencent.bkrepo.repository.service.node.impl +import com.google.common.cache.CacheBuilder +import com.google.common.cache.RemovalCause +import com.google.common.cache.RemovalListeners +import com.google.common.util.concurrent.ThreadFactoryBuilder import com.tencent.bkrepo.common.api.exception.ErrorCodeException import com.tencent.bkrepo.common.api.pojo.Page import com.tencent.bkrepo.common.api.util.Preconditions @@ -71,6 +75,10 @@ import org.springframework.data.mongodb.core.query.where import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime import java.time.format.DateTimeFormatter +import java.util.concurrent.ArrayBlockingQueue +import java.util.concurrent.Executors +import java.util.concurrent.ThreadPoolExecutor +import java.util.concurrent.TimeUnit /** * 节点基础服务,实现了CRUD基本操作 @@ -86,6 +94,37 @@ abstract class NodeBaseService( open val messageSupplier: MessageSupplier, ) : NodeService { + init { + // 定时清理过期缓存, 否则写入不频繁时可能很长时间也不触发数据库更新 + scheduler.scheduleWithFixedDelay( + { lastModifiedInfoUpdateCache.cleanUp() }, + UPDATE_LAST_MODIFIED_INFO_INTERVAL, + UPDATE_LAST_MODIFIED_INFO_INTERVAL, + TimeUnit.MINUTES + ) + } + + // 目录最后修改信息更新缓存, 缓存过期后才可能写入数据库 + private val lastModifiedInfoUpdateCache = CacheBuilder.newBuilder() + .maximumSize(1000) + .expireAfterWrite(UPDATE_LAST_MODIFIED_INFO_INTERVAL, TimeUnit.MINUTES) + .removalListener( + RemovalListeners.asynchronous, Pair> ( + { + if (it.cause == RemovalCause.EXPIRED || it.cause == RemovalCause.SIZE) { + val (projectId, repoName, fullPath) = it.key!! + val (lastModifiedBy, lastModifiedDate) = it.value!! + val query = NodeQueryHelper.nodeQuery(projectId, repoName, fullPath) + query.addCriteria(where(TNode::createdDate).lt(lastModifiedDate)) + val update = NodeQueryHelper.update(lastModifiedBy, lastModifiedDate) + nodeDao.updateFirst(query, update) + } + }, + updateLastModifiedInfoExecutor + ) + ) + .build, Pair>() + override fun getNodeDetail(artifact: ArtifactInfo, repoType: String?): NodeDetail? { with(artifact) { val node = nodeDao.findNode(projectId, repoName, getArtifactFullPath()) @@ -342,7 +381,13 @@ abstract class NodeBaseService( /** * 递归创建目录 */ - fun mkdirs(projectId: String, repoName: String, path: String, createdBy: String): List { + fun mkdirs( + projectId: String, + repoName: String, + path: String, + createdBy: String, + currentTime: LocalDateTime = LocalDateTime.now() + ): List { val nodes = mutableListOf() // 格式化 val fullPath = PathUtils.toFullPath(path) @@ -353,7 +398,7 @@ abstract class NodeBaseService( if (creatingNode == null) { val parentPath = PathUtils.resolveParent(fullPath) val name = PathUtils.resolveName(fullPath) - val creates = mkdirs(projectId, repoName, parentPath, createdBy) + val creates = mkdirs(projectId, repoName, parentPath, createdBy, currentTime) val node = TNode( folder = true, path = parentPath, @@ -365,17 +410,42 @@ abstract class NodeBaseService( projectId = projectId, repoName = repoName, createdBy = createdBy, - createdDate = LocalDateTime.now(), + createdDate = currentTime, lastModifiedBy = createdBy, - lastModifiedDate = LocalDateTime.now() + lastModifiedDate = currentTime ) doCreate(node) nodes.addAll(creates) nodes.add(node) + } else { + // 更新已存在的最近父目录的最后修改信息 + updateModifiedInfo(projectId, repoName, fullPath, createdBy, currentTime) } return nodes } + fun updateModifiedInfo( + projectId: String, + repoName: String, + fullPath: String, + modifiedBy: String, + modifiedDate: LocalDateTime = LocalDateTime.now() + ) { + if (!PathUtils.isRoot(fullPath)) { + lastModifiedInfoUpdateCache.put(Triple(projectId, repoName, fullPath), Pair(modifiedBy, modifiedDate)) + } + } + + fun cancelUpdateModifiedInfo(projectId: String, repoName: String, fullPathList: List) { + val keys = lastModifiedInfoUpdateCache.asMap().keys.filter { key -> + key.first == projectId && key.second == repoName && + fullPathList.any { key.third == it || key.third.startsWith(PathUtils.toPath(it)) } + } + if (keys.isNotEmpty()) { + lastModifiedInfoUpdateCache.invalidateAll(keys) + } + } + open fun checkConflictAndQuota(createRequest: NodeCreateRequest, fullPath: String): LocalDateTime? { with(createRequest) { val existNode = nodeDao.findNode(projectId, repoName, fullPath) @@ -410,6 +480,19 @@ abstract class NodeBaseService( companion object { private val logger = LoggerFactory.getLogger(NodeBaseService::class.java) private const val TOPIC = "bkbase_bkrepo_artifact_node_created" + private const val UPDATE_LAST_MODIFIED_INFO_INTERVAL = 5L + private val scheduler = Executors.newSingleThreadScheduledExecutor() + + // 更新目录最后修改信息任务线程池 + private val updateLastModifiedInfoExecutor = ThreadPoolExecutor( + 4, + 8, + 60, + TimeUnit.SECONDS, + ArrayBlockingQueue(1024), + ThreadFactoryBuilder().setNameFormat("update-lastModified-info-%d").build(), + ThreadPoolExecutor.CallerRunsPolicy() + ) private fun convert(tNode: TNode?): NodeInfo? { return tNode?.let { 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..3197bf3ac4 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 @@ -176,12 +176,14 @@ open class NodeDeleteSupport( var deletedNum = 0L var deletedSize = 0L val deleteTime = LocalDateTime.now() + var existFullPaths: List? = null val resourceKey = if (fullPaths == null) { "/$projectId/$repoName" } else if (fullPaths.size == 1) { "/$projectId/$repoName${fullPaths[0]}" } else { - "/$projectId/$repoName$fullPaths" + existFullPaths = nodeBaseService.listExistFullPath(projectId, repoName, fullPaths) + "/$projectId/$repoName$existFullPaths" } try { val updateResult = nodeDao.updateMulti(query, NodeQueryHelper.nodeDeleteUpdate(operator, deleteTime)) @@ -189,6 +191,18 @@ open class NodeDeleteSupport( if (deletedNum == 0L) { return NodeDeleteResult(deletedNum, deletedSize, deleteTime) } + // 获取被删除节点的父目录并更新修改信息 + val parentFullPaths = if (fullPaths?.size == 1) { + nodeBaseService.cancelUpdateModifiedInfo(projectId, repoName, fullPaths) + listOf(PathUtils.toFullPath(PathUtils.resolveParent(fullPaths[0]))) + } else { + existFullPaths?.map { PathUtils.toFullPath(PathUtils.resolveParent(it)) } + ?.distinct()?.filterNot { PathUtils.isRoot(it) } + ?.also { nodeBaseService.cancelUpdateModifiedInfo(projectId, repoName, it) } + } + parentFullPaths?.forEach { + nodeBaseService.updateModifiedInfo(projectId, repoName, it, operator, deleteTime) + } deletedSize = nodeBaseService.aggregateComputeSize(criteria.and(TNode::deleted).isEqualTo(deleteTime)) quotaService.decreaseUsedVolume(projectId, repoName, deletedSize) fullPaths?.forEach { publishEvent(buildDeletedEvent(projectId, repoName, it, operator)) } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeMoveCopySupport.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeMoveCopySupport.kt index db2b0f6d5a..6f65ab48be 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeMoveCopySupport.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeMoveCopySupport.kt @@ -97,6 +97,11 @@ open class NodeMoveCopySupport( } else { moveCopyFile(this) } + // 更新源节点父目录的最后修改信息 + if (move) { + val srcParentFullPath = PathUtils.toFullPath(resolveParent(srcNode.fullPath)) + nodeBaseService.updateModifiedInfo(srcRepo.projectId, srcRepo.name, srcParentFullPath, operator) + } } } @@ -301,6 +306,8 @@ open class NodeMoveCopySupport( val name = srcNode.name // 操作节点 doMoveCopy(this, srcNode, path, name) + // 更新dst目录的修改信息 + nodeBaseService.updateModifiedInfo(dstProjectId, dstRepoName, dstNode.fullPath, operator) PathUtils.combinePath(path, name) } val srcRootNodePath = toPath(srcNode.fullPath) diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRenameSupport.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRenameSupport.kt index 116479a0ad..2589546b34 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRenameSupport.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRenameSupport.kt @@ -73,6 +73,7 @@ open class NodeRenameSupport( val repoName = node.repoName val newPath = PathUtils.resolveParent(newFullPath) val newName = PathUtils.resolveName(newFullPath) + var modifiedCount = 0L // 检查新路径是否被占用 if (nodeDao.exists(projectId, repoName, newFullPath)) { @@ -93,12 +94,17 @@ open class NodeRenameSupport( val query = NodeQueryHelper.nodeListQuery(projectId, repoName, node.fullPath, listOption) nodeDao.find(query).forEach { doRename(it, newParentPath + it.name, operator) } // 删除自己 - nodeDao.remove(NodeQueryHelper.nodeQuery(projectId, repoName, node.fullPath)) + modifiedCount = nodeDao.remove(NodeQueryHelper.nodeQuery(projectId, repoName, node.fullPath)).deletedCount } else { // 修改自己 val selfQuery = NodeQueryHelper.nodeQuery(projectId, repoName, node.fullPath) val selfUpdate = NodeQueryHelper.nodePathUpdate(newPath, newName, operator) - nodeDao.updateFirst(selfQuery, selfUpdate) + modifiedCount = nodeDao.updateFirst(selfQuery, selfUpdate).modifiedCount + } + if (modifiedCount == 1L) { + // 更新父目录的最后修改信息 + val parentFullPath = PathUtils.toFullPath(PathUtils.resolveParent(node.fullPath)) + nodeBaseService.updateModifiedInfo(projectId, repoName, parentFullPath, operator) } } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRestoreSupport.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRestoreSupport.kt index b3eb0d925c..1acc1957db 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRestoreSupport.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/NodeRestoreSupport.kt @@ -35,6 +35,8 @@ import com.tencent.bkrepo.common.api.exception.ErrorCodeException import com.tencent.bkrepo.common.artifact.api.ArtifactInfo import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode import com.tencent.bkrepo.common.artifact.path.PathUtils.isRoot +import com.tencent.bkrepo.common.artifact.path.PathUtils.resolveParent +import com.tencent.bkrepo.common.artifact.path.PathUtils.toFullPath import com.tencent.bkrepo.common.security.util.SecurityUtils import com.tencent.bkrepo.repository.dao.NodeDao import com.tencent.bkrepo.repository.model.TNode @@ -65,7 +67,7 @@ import java.time.ZoneId * 节点统计接口实现 */ open class NodeRestoreSupport( - nodeBaseService: NodeBaseService + val nodeBaseService: NodeBaseService ) : NodeRestoreOperation { val nodeDao: NodeDao = nodeBaseService.nodeDao @@ -164,7 +166,11 @@ open class NodeRestoreSupport( } } val query = nodeDeletedPointQuery(projectId, repoName, fullPath, deletedTime) - restoreCount += nodeDao.updateFirst(query, nodeRestoreUpdate()).modifiedCount + val modifiedCount = nodeDao.updateFirst(query, nodeRestoreUpdate()).modifiedCount + restoreCount += modifiedCount + if (modifiedCount == 1L) { + nodeBaseService.updateModifiedInfo(projectId, repoName, toFullPath(resolveParent(fullPath)), operator) + } } } diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeRestoreSupport.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeRestoreSupport.kt index a2325867c3..ad956c9eab 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeRestoreSupport.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/service/node/impl/center/CommitEdgeCenterNodeRestoreSupport.kt @@ -29,6 +29,7 @@ package com.tencent.bkrepo.repository.service.node.impl.center import com.tencent.bkrepo.common.api.exception.ErrorCodeException import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode +import com.tencent.bkrepo.common.artifact.path.PathUtils import com.tencent.bkrepo.common.artifact.util.ClusterUtils import com.tencent.bkrepo.repository.model.TNode import com.tencent.bkrepo.repository.pojo.node.ConflictStrategy @@ -66,6 +67,11 @@ class CommitEdgeCenterNodeRestoreSupport( fullPath = fullPath, deleted = context.deletedTime ) - context.restoreCount += nodeDao.updateFirst(query, NodeQueryHelper.nodeRestoreUpdate()).modifiedCount + val modifiedCount = nodeDao.updateFirst(query, NodeQueryHelper.nodeRestoreUpdate()).modifiedCount + context.restoreCount += modifiedCount + if (modifiedCount == 1L) { + val parentFullPath = PathUtils.toFullPath(PathUtils.resolveParent(fullPath)) + nodeBaseService.updateModifiedInfo(context.projectId, context.repoName, parentFullPath, context.operator) + } } } 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..bc30a65935 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 @@ -156,9 +156,14 @@ class CommitEdgeCenterNodeServiceImpl( } val update = Update().addToSet(TNode::clusterNames.name).each(clusterNames) nodeMetadata?.let { update.set(TNode::metadata.name, it.map { convert(it) }) } + val currentTime = LocalDateTime.now() update.set(TNode::lastModifiedBy.name, operator) - update.set(TNode::lastModifiedDate.name, LocalDateTime.now()) - nodeDao.updateFirst(query, update) + update.set(TNode::lastModifiedDate.name, currentTime) + val modifiedCount = nodeDao.updateFirst(query, update).modifiedCount + if (modifiedCount == 1L) { + val parentFullPath = PathUtils.toFullPath(PathUtils.resolveParent(fullPath)) + super.updateModifiedInfo(projectId, repoName, parentFullPath, operator, currentTime) + } existNode.clusterNames = clusterNames logger.info("Create node[/$projectId/$repoName$fullPath],sha256[$sha256],region[$srcCluster] success.") return convertToDetail(existNode)!! diff --git a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/util/NodeQueryHelper.kt b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/util/NodeQueryHelper.kt index e16a1ca508..bc30fadc0d 100644 --- a/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/util/NodeQueryHelper.kt +++ b/src/backend/repository/biz-repository/src/main/kotlin/com/tencent/bkrepo/repository/util/NodeQueryHelper.kt @@ -198,9 +198,9 @@ object NodeQueryHelper { return update(operator).set(TNode::deleted.name, deleteTime) } - private fun update(operator: String): Update { + fun update(operator: String, time: LocalDateTime = LocalDateTime.now()): Update { return Update() - .set(TNode::lastModifiedDate.name, LocalDateTime.now()) + .set(TNode::lastModifiedDate.name, time) .set(TNode::lastModifiedBy.name, operator) } }