Language Management: cache all external resources, and leave out each application's own when reading #23233
BackVolobox task: VolosoftWorkspace#1928
Problem
In a microservice solution with an MVC or Blazor UI, Language Management > Language texts offers no AbpAccount, AbpIdentity or LeptonX in its Resource filter. The ABP 11.0.0-rc.2 smoke test (LT-01) failed this way on ms-mvc-mssql, ms-server-sqlite and ms-webapp-pg, and 10.7.1 did the same. The Angular microservice passed, which points to a race.
Cause
The list comes from LanguageAppService.GetResourcesAsync() in the LanguageService: its own resources plus ExternalLocalizationStore.GetResourceNamesAsync().
The store keeps all external resources in one distributed cache item, AbpAllLocalizationResourceRecords:All, but fills it with the records minus the resources of the application that fills it:
var cacheItems = (await LocalizationResourceRecordRepository.GetListAsync())
.Where(r => !LocalizationOptions.Resources.ContainsKey(r.Name)) // the filling application's own resources
.Select(CreateResourceCacheItem)
All services of a microservice solution share the distributed cache, so whichever service fills the item first decides what everyone else reads. When the AuthServer fills it, the resources it defines (AbpAccount, AbpIdentity, LeptonX, AbpUi, …) are gone for the LanguageService too.
Checked on a running ms-react-mongo (ABP 11.0.0-rc.2):
- The store (
MsReactMongo_Language.AbpLocalizationResources) has 40 resources, including AbpAccount, AbpIdentity and LeptonX. - The shared cache item in Redis (
c:AbpAllLocalizationResourceRecords,k:MsReactMongo:All) has 12. AbpAccount, AbpIdentity, LeptonX and AbpUi are not among them.
Change
ExternalLocalizationStore:
- the "all resources" cache item now holds all the records;
GetResourcesAsyncleaves out the caller's own resources after reading it, soGetResourceNamesAsyncdoes too.
The result for a single application is the same as before, and each application still gets only the resources it does not define itself.
Tests
New ExternalLocalizationStore_Tests.GetResourceNamesAsync_Should_Not_Depend_On_The_Application_That_Filled_The_Shared_Cache:
- The test application, which defines all the saved resources, reads first and gets none.
- A second store with the same cache and repository, but without those resources (another service), must get all of them.
- Against the old code: failed (the second store got the first one's filtered list).
- With this change: all 15 Language Management domain tests and all 15 application tests pass.
Note
An existing cache item filled by the old code keeps its filtered content until it is invalidated, by a new ExternalLocalizationSaver run, or until it expires.
Not in this PR: the UI apps' RemoteLocalizationContributor logs "Could not find the localization resource AbpAccount/LeptonX on the remote server!" tens of thousands of times. That is the UI looking for its own resources in the remote application configuration, a separate issue in Volo.Abp.AspNetCore.Mvc.Client.Common.
🤖 Generated with Claude Code