Commit 8142447 1 parent ee16515 commit 8142447 Copy full SHA for 8142447
File tree 1 file changed +13
-2
lines changed
orcid-core/src/main/java/org/orcid/core/api/rate_limit
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,12 @@ public class PapiRateLimitRedisClient {
28
28
@ Value ("${org.orcid.papi.rate.limit.redisCacheExpiryInSec:172800}" )
29
29
private int CASH_EXPIRY_IN_SECONDS ; // caching for 2 days to have time to
30
30
// synch with DB
31
+
32
+ @ Value ("${org.orcid.papi.rate.limit.anonymous.requests:10000}" )
33
+ private int anonymousRequestLimit ;
34
+
35
+ @ Value ("${org.orcid.papi.rate.limit.known.requests:40000}" )
36
+ private int knownRequestLimit ;
31
37
32
38
@ Autowired
33
39
private PublicApiDailyRateLimitDao papiRateLimitingDao ;
@@ -82,10 +88,15 @@ else if(StringUtils.isNotEmpty(redisRateLimitEntity.getClientId())){
82
88
pgRateLimitEntity = papiRateLimitingDao .findByClientIdAndRequestDate (redisRateLimitEntity .getClientId (), requestDate );
83
89
isClient = true ;
84
90
}
91
+ //only save the exceeded limits
85
92
if (pgRateLimitEntity != null ) {
86
- papiRateLimitingDao .updatePublicApiDailyRateLimit (pgRateLimitEntity , isClient );
93
+ if (((pgRateLimitEntity .getRequestCount () > knownRequestLimit ) && isClient ) || ((pgRateLimitEntity .getRequestCount () > anonymousRequestLimit ) && !isClient )) {
94
+ papiRateLimitingDao .updatePublicApiDailyRateLimit (pgRateLimitEntity , isClient );
95
+ }
87
96
} else {
88
- papiRateLimitingDao .persist (redisObjJsonToEntity (allValuesForKey .get (key )));
97
+ if (((redisRateLimitEntity .getRequestCount () > knownRequestLimit ) && isClient ) || ((redisRateLimitEntity .getRequestCount () > anonymousRequestLimit ) && !isClient )) {
98
+ papiRateLimitingDao .persist (redisRateLimitEntity );
99
+ }
89
100
}
90
101
redisClient .remove (key );
91
102
}
You can’t perform that action at this time.
0 commit comments