actionlimiter 1.0.0.beta2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a45ffa8e18273c24ca2f9407c0909fbc719fb88c49295676256940eecfe3a73f
4
- data.tar.gz: e0904db27c728ac00ce0774533a33bf154902682cc867a0a5ed8a313d8c04037
3
+ metadata.gz: f6d76f1d615f1668d12ed5a37407579aa6f398f622b409f1e425d40a5e3d22b9
4
+ data.tar.gz: b39112826f0e034c2758fb41578ed9b936d1a3d305d97a157391065e64b13b17
5
5
  SHA512:
6
- metadata.gz: 99d0dc2ec88875dee1d954c146b0c1d2aefb9aa3bcce808e39dc0fb5dae936b176123a3e0ef78691744fd531c9fbc6c5303057738aba636718308cccee1c6527
7
- data.tar.gz: 642c0875a2112631fc652c869cef869b6953e36244c55d4d547c07269e250a57ac34767c6386ec42652384a1078dcde3c4cd66590576dac5acb54c84f4813b1d
6
+ metadata.gz: e9919e7a48c0206b3a8ad53ae77ea1d1881823dbad7dfd22620922f86560184426c0880cd3130eabcc069e5dbf1adba13e84d0f0d86606d5c81d8cad40f61f2b
7
+ data.tar.gz: '0294d97901f27645b413ad03e48e6dfaf11102b6154c7ba6951f7c8ac0a331bc7fd39701877d969ba6c03afd6ca6f2672d0f7eb91ca7a43d5103e710b80e9196'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActionLimiter
2
2
 
3
- [![Unit Test](https://github.com/angryboat/actionlimiter/actions/workflows/testing.yml/badge.svg)](https://github.com/angryboat/actionlimiter/actions/workflows/testing.yml) [![Linters](https://github.com/angryboat/actionlimiter/actions/workflows/linting.yml/badge.svg)](https://github.com/angryboat/actionlimiter/actions/workflows/linting.yml)
3
+ [![Ruby Gem](https://github.com/angryboat/actionlimiter/actions/workflows/ruby-gem.yml/badge.svg?event=push)](https://github.com/angryboat/actionlimiter/actions/workflows/ruby-gem.yml)
4
4
 
5
5
  Provides Redis backed rate limiting for Rails applications.
6
6
 
@@ -63,7 +63,7 @@ module ActionLimiter
63
63
  def _call(env)
64
64
  remote_ip = env.fetch('action_dispatch.remote_ip')
65
65
  bucket_key = Digest::MD5.hexdigest(remote_ip.to_s)
66
- bucket = @token_bucket.increment(bucket_key, Time.now)
66
+ bucket = @token_bucket.increment_and_return_bucket(bucket_key, Time.now)
67
67
 
68
68
  env['action_limiter.ip_bucket'] = bucket
69
69
 
@@ -13,6 +13,6 @@ local bucket_name = KEYS[1]
13
13
 
14
14
  redis.call('ZREMRANGEBYSCORE', bucket_name, '-inf', min)
15
15
  redis.call('ZADD', bucket_name, ts, ts)
16
- redis.call('EXPIRE', bucket_name, period * 5)
16
+ redis.call('EXPIRE', bucket_name, period + 2)
17
17
 
18
18
  return redis.call('ZCARD', bucket_name)
@@ -43,9 +43,6 @@ module ActionLimiter
43
43
  @period = period.to_i
44
44
  @size = size.to_i
45
45
  @namespace = namespace&.to_s || 'action_limiter/token_bucket'
46
- @script_hash = ActionLimiter.with_redis_connection do |connection|
47
- connection.script(:load, ActionLimiter::SCRIPTS.fetch(:token_bucket))
48
- end
49
46
  end
50
47
 
51
48
  ##
@@ -78,7 +75,7 @@ module ActionLimiter
78
75
  def increment_and_return_bucket(bucket, time)
79
76
  ActionLimiter.instrument('action_limiter.token_bucket.increment') do
80
77
  ActionLimiter.with_redis_connection do |connection|
81
- value = connection.evalsha(@script_hash, [bucket_key(bucket)], [period.to_s, time.to_f])
78
+ value = connection.evalsha(script_hash, [bucket_key(bucket)], [period.to_s, time.to_f.to_s])
82
79
  Bucket.new(name: bucket, value: value, max_size: size, period: period)
83
80
  end
84
81
  end
@@ -86,6 +83,12 @@ module ActionLimiter
86
83
 
87
84
  private
88
85
 
86
+ def script_hash
87
+ @script_hash ||= ActionLimiter.with_redis_connection do |connection|
88
+ connection.script(:load, ActionLimiter::SCRIPTS.fetch(:token_bucket))
89
+ end
90
+ end
91
+
89
92
  def bucket_key(bucket)
90
93
  "#{namespace}/#{bucket}"
91
94
  end
@@ -3,5 +3,5 @@
3
3
  module ActionLimiter
4
4
  ##
5
5
  # The current version number
6
- VERSION = '1.0.0.beta2'
6
+ VERSION = '1.0.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionlimiter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maddie Schipper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-21 00:00:00.000000000 Z
11
+ date: 2022-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -50,6 +50,20 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: pry
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
53
67
  description: 'Redis backed token bucket rate limting implementation.
54
68
 
55
69
  '
@@ -93,9 +107,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
107
  version: '2.7'
94
108
  required_rubygems_version: !ruby/object:Gem::Requirement
95
109
  requirements:
96
- - - ">"
110
+ - - ">="
97
111
  - !ruby/object:Gem::Version
98
- version: 1.3.1
112
+ version: '0'
99
113
  requirements: []
100
114
  rubygems_version: 3.1.6
101
115
  signing_key: