From f73222fd7283882f5ed770be6a2421525cdb357b Mon Sep 17 00:00:00 2001 From: Jeff Putz Date: Wed, 31 Jan 2024 20:24:21 -0500 Subject: [PATCH] Change GetUsersByPointTotals to fix caching bug #358 --- src/PopForums.Sql/Repositories/UserRepository.cs | 8 ++++---- src/PopForums/Repositories/IUserRepository.cs | 2 +- src/PopForums/Services/UserService.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/PopForums.Sql/Repositories/UserRepository.cs b/src/PopForums.Sql/Repositories/UserRepository.cs index ef4c703d..6aea5147 100644 --- a/src/PopForums.Sql/Repositories/UserRepository.cs +++ b/src/PopForums.Sql/Repositories/UserRepository.cs @@ -233,19 +233,19 @@ await _sqlObjectFactory.GetConnection().UsingAsync(connection => return list.Result.ToList(); } - public Dictionary GetUsersByPointTotals(int top) + public Dictionary GetUsersByPointTotals(int top) { var key = CacheKeys.PointTotals + top; - var cacheObject = _cacheHelper.GetCacheObject>(key); + var cacheObject = _cacheHelper.GetCacheObject>(key); if (cacheObject != null) return cacheObject; - var list = new Dictionary(); + var list = new Dictionary(); _sqlObjectFactory.GetConnection().Using(connection => connection.Query( $"SELECT TOP {top} {PopForumsUserColumns}, pf_Profile.Points FROM pf_PopForumsUser JOIN pf_Profile ON pf_PopForumsUser.UserID = pf_Profile.UserID ORDER BY pf_Profile.Points DESC", (user, points) => { - list.Add(user, points); + list.Add(user.UserID, (user, points)); return user; }, splitOn: "Points")); _cacheHelper.SetCacheObject(key, list, 60); diff --git a/src/PopForums/Repositories/IUserRepository.cs b/src/PopForums/Repositories/IUserRepository.cs index 3c6de740..2ec293e2 100644 --- a/src/PopForums/Repositories/IUserRepository.cs +++ b/src/PopForums/Repositories/IUserRepository.cs @@ -91,7 +91,7 @@ public interface IUserRepository Task DeleteUser(User user); Task> GetUsersFromIDs(IList ids); Task GetTotalUsers(); - Dictionary GetUsersByPointTotals(int top); + Dictionary GetUsersByPointTotals(int top); Task> GetRecentUsers(); Task UpdateTokenExpiration(User user, DateTime? tokenExpiration); Task UpdateRefreshToken(User user, string refreshToken); diff --git a/src/PopForums/Services/UserService.cs b/src/PopForums/Services/UserService.cs index 8b943b7c..6a19d9b4 100644 --- a/src/PopForums/Services/UserService.cs +++ b/src/PopForums/Services/UserService.cs @@ -42,7 +42,7 @@ public interface IUserService Task> GetUsersFromIDs(IList ids); Task GetTotalUsers(); Task> GetSubscribedUsers(); - Dictionary GetUsersByPointTotals(int top); + Dictionary GetUsersByPointTotals(int top); Task> GetRecentUsers(); Task UpdateTokenExpiration(User user, DateTime? tokenExpiration); Task UpdateRefreshToken(User user, string refreshToken); @@ -529,7 +529,7 @@ public async Task> GetSubscribedUsers() return await _userRepository.GetSubscribedUsers(); } - public Dictionary GetUsersByPointTotals(int top) + public Dictionary GetUsersByPointTotals(int top) { return _userRepository.GetUsersByPointTotals(top); }