From b3553dc2767103128724e16dbadd8a61ad81d052 Mon Sep 17 00:00:00 2001 From: colin Date: Wed, 30 Jul 2025 15:45:44 +0800 Subject: [PATCH] fix(localization): fixed #1292 --- .../LocalizationTextStoreCache.cs | 53 ++----------------- 1 file changed, 4 insertions(+), 49 deletions(-) diff --git a/aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Domain/LINGYUN/Abp/LocalizationManagement/LocalizationTextStoreCache.cs b/aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Domain/LINGYUN/Abp/LocalizationManagement/LocalizationTextStoreCache.cs index 851f7679e..0a5f84499 100644 --- a/aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Domain/LINGYUN/Abp/LocalizationManagement/LocalizationTextStoreCache.cs +++ b/aspnet-core/modules/localization-management/LINGYUN.Abp.LocalizationManagement.Domain/LINGYUN/Abp/LocalizationManagement/LocalizationTextStoreCache.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Localization; -using System; using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Caching; @@ -24,12 +23,7 @@ public class LocalizationTextStoreCache : ILocalizationTextStoreCache, ISingleto public virtual void Fill(LocalizationResourceBase resource, string cultureName, Dictionary dictionary) { - var cacheItem = GetCacheItem(resource, cultureName); - - foreach (var text in cacheItem.Texts) - { - dictionary[text.Key] = new LocalizedString(text.Key, text.Value); - } + // 同步本地化函数不执行, 阻塞线程影响性能 } public async virtual Task FillAsync(LocalizationResourceBase resource, string cultureName, Dictionary dictionary) @@ -44,52 +38,13 @@ public class LocalizationTextStoreCache : ILocalizationTextStoreCache, ISingleto public virtual LocalizedString GetOrNull(LocalizationResourceBase resource, string cultureName, string name) { - var cacheItem = GetCacheItem(resource, cultureName); - - var value = cacheItem.Texts.GetOrDefault(name); - if (value.IsNullOrWhiteSpace()) - { - return null; - } - - return new LocalizedString(name, value); - } - - protected virtual LocalizationTextCacheItem GetCacheItem(LocalizationResourceBase resource, string cultureName) - { - var cacheKey = LocalizationTextCacheItem.CalculateCacheKey(resource.ResourceName, cultureName); - var cacheItem = LocalizationTextCache.Get(cacheKey); - if (cacheItem != null) - { - return cacheItem; - } - - var setTexts = new Dictionary(); - using (var scope = ServiceScopeFactory.CreateScope()) - { - var provider = scope.ServiceProvider.GetRequiredService(); - using (provider.Change(false)) - { - var repo = scope.ServiceProvider.GetRequiredService(); -#pragma warning disable CS0618 - var texts = repo.GetList(resource.ResourceName, cultureName); -#pragma warning restore CS0618 - foreach (var text in texts) - { - setTexts[text.Key] = text.Value; - } - } - } - - cacheItem = new LocalizationTextCacheItem(resource.ResourceName, cultureName, setTexts); - - LocalizationTextCache.Set(cacheKey, cacheItem); - - return cacheItem; + // 同步本地化函数不执行, 阻塞线程影响性能 + return null; } protected async virtual Task GetCacheItemAsync(LocalizationResourceBase resource, string cultureName) { + // 异步本地化函数不受影响 var cacheKey = LocalizationTextCacheItem.CalculateCacheKey(resource.ResourceName, cultureName); var cacheItem = await LocalizationTextCache.GetAsync(cacheKey); if (cacheItem != null)