From f3a17420952a70611cfaca34e790122f7c21b5b6 Mon Sep 17 00:00:00 2001 From: yaoxuwan Date: Wed, 18 Oct 2023 18:04:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20fs-server=E6=94=AF=E6=8C=81=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E4=BC=9A=E8=AF=9D=E7=AE=A1=E7=90=86=20#1275?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bkrepo/fs/server/service/ClientService.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/ClientService.kt b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/ClientService.kt index fa84456471..7ce4b06dff 100644 --- a/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/ClientService.kt +++ b/src/backend/fs/boot-fs-server/src/main/kotlin/com/tencent/bkrepo/fs/server/service/ClientService.kt @@ -41,7 +41,6 @@ import com.tencent.bkrepo.fs.server.request.ClientCreateRequest import com.tencent.bkrepo.fs.server.utils.ReactiveSecurityUtils import org.springframework.data.mongodb.core.query.Criteria import org.springframework.data.mongodb.core.query.Query -import org.springframework.data.mongodb.core.query.Update import org.springframework.data.mongodb.core.query.isEqualTo import java.time.LocalDateTime @@ -85,12 +84,11 @@ class ClientService( .and(TClient::repoName.name).isEqualTo(repoName) .and(TClient::id.name).isEqualTo(clientId) ) - val update = Update().set(TClient::heartbeatTime.name, LocalDateTime.now()) - .set(TClient::online.name, true) - val result = clientRepository.upsert(query, update) - if (result.matchedCount == 0L) { - throw ErrorCodeException(CommonMessageCode.RESOURCE_NOT_FOUND, clientId) - } + val client = clientRepository.findOne(query) + ?: throw ErrorCodeException(CommonMessageCode.RESOURCE_NOT_FOUND, clientId) + client.heartbeatTime = LocalDateTime.now() + client.online = true + clientRepository.save(client) } private suspend fun insertClient(request: ClientCreateRequest): TClient {