From 2dad71d882d5eb61282e8b1c2bd4e775b5972f92 Mon Sep 17 00:00:00 2001 From: Qinyouzeng <102203523+Qinyouzeng@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:46:46 +0800 Subject: [PATCH] Fix: split data and cache init (#645) * fix: split data and cache init * chore: upgrade sdk version --- Directory.Build.props | 4 ++-- .../Services/ConfigObjectDomainService.cs | 21 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 8a65bc8..b0e6507 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 1.2.0-preview.4 - 1.2.1-preview.8 + 1.2.0-preview.5 + 1.2.1-preview.10 \ No newline at end of file diff --git a/Masa.Dcc.Infrastructure.Domain/Services/ConfigObjectDomainService.cs b/Masa.Dcc.Infrastructure.Domain/Services/ConfigObjectDomainService.cs index 859a823..2991f18 100644 --- a/Masa.Dcc.Infrastructure.Domain/Services/ConfigObjectDomainService.cs +++ b/Masa.Dcc.Infrastructure.Domain/Services/ConfigObjectDomainService.cs @@ -526,13 +526,6 @@ public async Task InitConfigObjectAsync( foreach (var configObject in configObjects) { var configObjectName = configObject.Key; - var key = $"{environmentName}-{clusterName}-{appId}-{configObjectName}".ToLower(); - var redisData = await _memoryCacheClient.GetAsync(key); - if (redisData != null) - { - continue; - } - string content = configObject.Value; if (isEncryption) content = EncryptContent(content); @@ -573,8 +566,18 @@ public async Task InitConfigObjectAsync( } } } - await _configObjectRepository.AddAsync(newConfigObject); - await _unitOfWork.SaveChangesAsync(); + if (await _configObjectRepository.FindAsync(x => x.Name == newConfigObject.Name && x.Type == newConfigObject.Type) == null) + { + await _configObjectRepository.AddAsync(newConfigObject); + await _unitOfWork.SaveChangesAsync(); + } + + var key = $"{environmentName}-{clusterName}-{appId}-{configObjectName}".ToLower(); + var redisData = await _memoryCacheClient.GetAsync(key); + if (redisData != null) + { + continue; + } var releaseModel = new AddConfigObjectReleaseDto {