@@ -9,43 +9,53 @@ const routeMatcher = require('./route-matcher')(triggersNotificationPaths)
99const triggersNotification = throttlingPlugin . triggersNotification =
1010 routeMatcher . test . bind ( routeMatcher )
1111
12+ const groups = { }
13+
14+ const createGroups = function ( Bottleneck , common ) {
15+ groups . global = new Bottleneck . Group ( {
16+ id : 'octokit-global' ,
17+ maxConcurrent : 1 ,
18+ ...common
19+ } )
20+ groups . write = new Bottleneck . Group ( {
21+ id : 'octokit-write' ,
22+ maxConcurrent : 1 ,
23+ minTime : 1000 ,
24+ ...common
25+ } )
26+ groups . notifications = new Bottleneck . Group ( {
27+ id : 'octokit-notifications' ,
28+ maxConcurrent : 1 ,
29+ minTime : 3000 ,
30+ ...common
31+ } )
32+ }
33+
1234function throttlingPlugin ( octokit , octokitOptions = { } ) {
1335 const {
1436 enabled = true ,
1537 Bottleneck = BottleneckLight ,
1638 id = 'no-id' ,
39+ timeout = 1000 * 60 * 2 , // Redis TTL: 2 minutes
1740 connection
1841 } = octokitOptions . throttle || { }
1942 if ( ! enabled ) {
2043 return
2144 }
22- const common = {
23- connection,
24- timeout : 1000 * 60 * 10 // Redis TTL: 10 minutes
45+ const common = { connection, timeout }
46+
47+ if ( groups . global == null ) {
48+ createGroups ( Bottleneck , common )
2549 }
50+
2651 const state = Object . assign ( {
2752 clustering : connection != null ,
2853 triggersNotification,
2954 minimumAbuseRetryAfter : 5 ,
3055 retryAfterBaseValue : 1000 ,
31- globalLimiter : new Bottleneck ( {
32- id : `octokit-global-${ id } ` ,
33- maxConcurrent : 1 ,
34- ...common
35- } ) ,
36- writeLimiter : new Bottleneck ( {
37- id : `octokit-write-${ id } ` ,
38- maxConcurrent : 1 ,
39- minTime : 1000 ,
40- ...common
41- } ) ,
42- triggersNotificationLimiter : new Bottleneck ( {
43- id : `octokit-notifications-${ id } ` ,
44- maxConcurrent : 1 ,
45- minTime : 3000 ,
46- ...common
47- } ) ,
48- retryLimiter : new Bottleneck ( )
56+ retryLimiter : new Bottleneck ( ) ,
57+ id,
58+ ...groups
4959 } , octokitOptions . throttle )
5060
5161 if ( typeof state . onAbuseLimit !== 'function' || typeof state . onRateLimit !== 'function' ) {
0 commit comments