ip 请求次数限制18

This commit is contained in:
GYJ 2025-03-24 12:26:36 +08:00
parent da9db2f8b1
commit 69cf777a8f
1 changed files with 12 additions and 13 deletions

View File

@ -63,22 +63,21 @@ public class IpAccessCounter {
removeCount.set(0);
long currentTime = System.currentTimeMillis();
Set<String> removedIps = new HashSet<>();
for (Map.Entry<String, List<Long>> entry : IP_ACCESS_TIMES.entrySet()) {
List<Long> accessTimes = entry.getValue();
if (accessTimes == null || accessTimes.isEmpty()) {
continue;
}
accessTimes.removeIf(time -> currentTime - time > ONE_MINUTE);
if (accessTimes.isEmpty()) {
removedIps.add(entry.getKey());
}
}
// IP_ACCESS_TIMES.forEach((ip, accessTimes) -> {
// for (Map.Entry<String, List<Long>> entry : IP_ACCESS_TIMES.entrySet()) {
// List<Long> accessTimes = entry.getValue();
// accessTimes.removeIf(time -> currentTime - time > ONE_MINUTE);
// if (accessTimes.isEmpty()) {
// removedIps.add(ip);
// removedIps.add(entry.getKey());
// }
// });
// }
IP_ACCESS_TIMES.forEach((ip, accessTimes) -> {
if (accessTimes != null && !accessTimes.isEmpty()) {
accessTimes.removeIf(time -> currentTime - time > ONE_MINUTE);
if (accessTimes.isEmpty()) {
removedIps.add(ip);
}
}
});
removedIps.forEach(IP_ACCESS_TIMES::remove);
Set<String> removedBlacklistIps = new HashSet<>();