|
43 | 43 | public class UserServiceImpl implements UserService { |
44 | 44 |
|
45 | 45 | private static final int DAILY_LIMIT_SECONDS = 86_400; |
| 46 | + private static final int USER_INFO_UPDATE_INTERVAL_SECONDS = 180; |
46 | 47 | private static final long MAX_AVATAR_SIZE = 2 * 1024 * 1024; |
47 | 48 | private static final Set<String> ALLOWED_AVATAR_TYPES = Set.of( |
48 | 49 | "image/jpeg", "image/png", "image/webp", "image/gif" |
@@ -259,14 +260,19 @@ private void markPasswordResetDaily(String email) { |
259 | 260 |
|
260 | 261 | private void checkUserInfoUpdateDailyLimit(Long userId) { |
261 | 262 | String key = Constants.USER_INFO_UPDATE_DAILY_KEY + ':' + userId; |
262 | | - if (redisTemplate.hasKey(key)) { |
263 | | - throw new IllegalArgumentException("今日已更新过用户资料,请明天再试"); |
| 263 | + long ttl = redisTemplate.getExpire(key, TimeUnit.SECONDS); |
| 264 | + if (ttl > 0) { |
| 265 | + long minutes = ttl / 60; |
| 266 | + long seconds = ttl % 60; |
| 267 | + throw new IllegalArgumentException( |
| 268 | + "用户信息更新过于频繁,请 %d 分 %d 秒后再试".formatted(minutes, seconds) |
| 269 | + ); |
264 | 270 | } |
265 | 271 | } |
266 | 272 |
|
267 | 273 | private void markUserInfoUpdateDaily(Long userId) { |
268 | 274 | String key = Constants.USER_INFO_UPDATE_DAILY_KEY + ':' + userId; |
269 | | - redisTemplate.opsForValue().set(key, "1", DAILY_LIMIT_SECONDS, TimeUnit.SECONDS); |
| 275 | + redisTemplate.opsForValue().set(key, "1", USER_INFO_UPDATE_INTERVAL_SECONDS, TimeUnit.SECONDS); |
270 | 276 | } |
271 | 277 |
|
272 | 278 | private FlowUserVo loadUserVo(Long userId) { |
|
0 commit comments