peformance verbesserungen
This commit is contained in:
@@ -6,6 +6,7 @@ namespace timetracker.Client.Services;
|
||||
public class ClientTimetrackerService : ITimetrackerService
|
||||
{
|
||||
private readonly HttpClient _http;
|
||||
private AppSettings? _cachedSettings;
|
||||
|
||||
public ClientTimetrackerService(HttpClient http)
|
||||
{
|
||||
@@ -24,12 +25,19 @@ public class ClientTimetrackerService : ITimetrackerService
|
||||
|
||||
public async Task<AppSettings> GetSettingsAsync(int userId)
|
||||
{
|
||||
return await _http.GetFromJsonAsync<AppSettings>($"api/tracker/settings/{userId}") ?? new AppSettings { UserId = userId };
|
||||
if (_cachedSettings != null && _cachedSettings.UserId == userId)
|
||||
{
|
||||
return _cachedSettings;
|
||||
}
|
||||
var settings = await _http.GetFromJsonAsync<AppSettings>($"api/tracker/settings/{userId}");
|
||||
_cachedSettings = settings ?? new AppSettings { UserId = userId };
|
||||
return _cachedSettings;
|
||||
}
|
||||
|
||||
public async Task SaveSettingsAsync(AppSettings settings)
|
||||
{
|
||||
await _http.PostAsJsonAsync("api/tracker/settings", settings);
|
||||
_cachedSettings = settings;
|
||||
}
|
||||
|
||||
public async Task<List<VacationDay>> GetVacationDaysAsync(int userId, int year)
|
||||
|
||||
Reference in New Issue
Block a user