Skip to content

Commit b9eb582

Browse files
committed
Minor logic change.
1 parent 84e574f commit b9eb582

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/org/barcodeapi/server/cache/LimiterCache.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,24 @@ public class LimiterCache {
3737
public static CachedLimiter getLimiter(Subscriber sub, String address) {
3838
LibMetrics.hitMethodRunCounter();
3939

40+
// User ID is customer or address
41+
String userID = (sub != null) ? sub.getCustomer() : address;
42+
4043
// Determine if limiter exists
4144
CachedLimiter limiter;
42-
if (_LIMITERS.has(address)) {
45+
if (_LIMITERS.has(userID)) {
4346

4447
// Get the existing limiter from the cache
45-
limiter = (CachedLimiter) _LIMITERS.get(address);
48+
limiter = (CachedLimiter) _LIMITERS.get(userID);
4649
} else {
4750

4851
// Determine enforce / limits for the new limiter
4952
int limit = (sub != null) ? sub.getLimit() : DEFLIMIT_RATE;
5053
boolean enforce = (sub != null) ? sub.isEnforced() : DEFLIMIT_ENFORCE;
5154

5255
// Create a new limiter and add it to the cache
53-
limiter = new CachedLimiter(enforce, address, limit);
54-
_LIMITERS.put(address, limiter);
56+
limiter = new CachedLimiter(enforce, userID, limit);
57+
_LIMITERS.put(userID, limiter);
5558
}
5659

5760
// Return the limiter

0 commit comments

Comments
 (0)