Implemented update All UserInfo

This commit is contained in:
Casper Sparre 2026-02-19 21:45:06 +01:00
parent bad6cc740f
commit d417741702

View File

@ -252,7 +252,61 @@ internal class Worker(IServiceProvider serviceProvider)
private async Task UpdateUserInfoAsync() private async Task UpdateUserInfoAsync()
{ {
await _dbService.CreateUsersDb([]);
await _dbService.InitializeUserInfoTablesAsync();
Dictionary<string, long> users = await _dbService.GetUsersAsync();
Console.WriteLine();
Log.Information("Updating User Info for '{UserCount}' users", users.Count);
AnsiConsole.Markup($"[green]Updating User Info for '{users.Count}' users\n[/]");
await AnsiConsole.Progress()
.Columns(new ProgressBarColumn(), new PercentageColumn(), new TaskDescriptionColumn { Alignment = Justify.Left })
.StartAsync(RunUpdateAsync);
async Task RunUpdateAsync(ProgressContext context)
{
ProgressTask? updateTask = null;
int maxUsernameLength = users.Keys.Max(s => s.Length);
foreach ((string username, long userId) in users)
{
string description = $"Updating '{username}'".PadRight(11 + maxUsernameLength);
double prevValue = updateTask?.Value ?? 0;
updateTask = context.AddTask(description, true, users.Count);
updateTask.Value = prevValue;
using (LogContext.PushProperty("Username", username))
using (LogContext.PushProperty("UserId", userId))
using (LogContext.PushProperty("UserNum", prevValue + 1))
using (LogContext.PushProperty("UserTotal", users.Count))
{
try
{
Log.Information("[{UserNum:0} of {UserTotal}] Updating User Info for for: {Username:l}");
UserEntities.UserInfo? userInfo = await _apiService.GetDetailedUserInfoAsync($"/users/{username}");
await _dbService.UpdateUserInfoAsync(userInfo);
updateTask.Description = $"{description} - COMPLETE";
}
catch (Exception ex)
{
Log.Warning(ex, "[{UserNum:0} of {UserTotal}] Failed to update User Info for: {Username:l}");
AnsiConsole.Markup($"[red]Failed to update User Info for '{username}'\n[/]");
updateTask.Description = $"{description} - FAILED: {ex.Message}";
}
finally
{
updateTask.Increment(1);
updateTask.StopTask();
}
}
}
}
} }
private async Task<Dictionary<string, long>> GetUsersFromSpecificListsAsync(UserListResult allUsersAndLists, string[] listNames) private async Task<Dictionary<string, long>> GetUsersFromSpecificListsAsync(UserListResult allUsersAndLists, string[] listNames)