Implemented user image cache update on settings update

This commit is contained in:
2025-11-20 21:03:48 +01:00
parent 5925f1a0f1
commit 116b47cdc0
2 changed files with 8 additions and 0 deletions

View File

@@ -56,7 +56,13 @@ public class SettingsController : Controller
ErrorMessage = "adminUpdateRequestModel is null" ErrorMessage = "adminUpdateRequestModel is null"
}; };
} }
AdminSettingsModel currentSettingsModel = await _ldap.GetAdminSettingsModelAsync();
await _ldap.SetAdminSettingsModelAsync(adminSettingsRequestModel.AdminSettingsModel); await _ldap.SetAdminSettingsModelAsync(adminSettingsRequestModel.AdminSettingsModel);
if (adminSettingsRequestModel.AdminSettingsModel.UserImagePreloadType != currentSettingsModel.UserImagePreloadType)
{
IEnumerable<UserModel> users = await _ldap.ListUsersAsync();
Task _ = ImageHelper.PreloadUsers(users, adminSettingsRequestModel.AdminSettingsModel.UserImagePreloadType);
}
return new() { return new() {
Success = true Success = true
}; };

View File

@@ -10,6 +10,7 @@ public static class ImageHelper
public static Dictionary<int, Dictionary<string, byte[]>> ImageCache = []; public static Dictionary<int, Dictionary<string, byte[]>> ImageCache = [];
public static byte[] ResizeAndConvertToWebp(string imageString, int size = 32) public static byte[] ResizeAndConvertToWebp(string imageString, int size = 32)
{ {
if (imageString.Length == 0) return [];
if (ImageCache.TryGetValue(size, out Dictionary<string, byte[]>? sizeCache) if (ImageCache.TryGetValue(size, out Dictionary<string, byte[]>? sizeCache)
&& sizeCache.TryGetValue(imageString, out byte[]? result) && result.Length > 0) && sizeCache.TryGetValue(imageString, out byte[]? result) && result.Length > 0)
{ {
@@ -49,6 +50,7 @@ public static class ImageHelper
{ {
ResizeAndConvertToWebp(user.JpegPhoto, 256); ResizeAndConvertToWebp(user.JpegPhoto, 256);
} }
Thread.Sleep(10);
} }
} }
} }