Added cache to the number of cultures

This commit is contained in:
Thorsten Sommer 2022-07-30 23:17:57 +02:00
parent 276fa51e92
commit 9419642525
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -212,9 +212,15 @@ public static class AppSettings
#region Translation Settings
#region Number of cultures
private static int CACHE_NUMBER_OF_CULTURES = -1;
public static async Task<int> GetNumberCultures()
{
// When possible, use the cache:
if (CACHE_NUMBER_OF_CULTURES > -1)
return CACHE_NUMBER_OF_CULTURES;
// Get the database:
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
@ -223,8 +229,12 @@ public static class AppSettings
// We have at least one default culture:
if(count == 0)
{
CACHE_NUMBER_OF_CULTURES = 1;
return 1;
}
CACHE_NUMBER_OF_CULTURES = count;
return count;
}
@ -291,6 +301,10 @@ public static class AppSettings
await db.Settings.AddAsync(setting);
await db.SaveChangesAsync();
// Update the number of cultures cache:
if(CACHE_NUMBER_OF_CULTURES > -1)
CACHE_NUMBER_OF_CULTURES++;
}
}