Resolve "Component: Settings" #69
@@ -213,8 +213,14 @@ public static class AppSettings
|
|||||||
|
|
||||||
#region Number of cultures
|
#region Number of cultures
|
||||||
|
|
||||||
|
private static int CACHE_NUMBER_OF_CULTURES = -1;
|
||||||
|
|
||||||
public static async Task<int> GetNumberCultures()
|
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:
|
// Get the database:
|
||||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||||
|
|
||||||
@@ -223,8 +229,12 @@ public static class AppSettings
|
|||||||
|
|
||||||
// We have at least one default culture:
|
// We have at least one default culture:
|
||||||
if(count == 0)
|
if(count == 0)
|
||||||
|
{
|
||||||
|
CACHE_NUMBER_OF_CULTURES = 1;
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CACHE_NUMBER_OF_CULTURES = count;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,6 +301,10 @@ public static class AppSettings
|
|||||||
|
|
||||||
await db.Settings.AddAsync(setting);
|
await db.Settings.AddAsync(setting);
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
|
|
||||||
|
// Update the number of cultures cache:
|
||||||
|
if(CACHE_NUMBER_OF_CULTURES > -1)
|
||||||
|
CACHE_NUMBER_OF_CULTURES++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user