Skip to content

Commit 4958a8d

Browse files
committed
Only modify the keys if there are duplicates
1 parent 2da94d7 commit 4958a8d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Illuminate/Cache/RateLimiter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ public function limiter($name)
7676
return $result;
7777
}
7878

79+
$duplicates = collect($result)->duplicates('key');
80+
81+
if ($duplicates->isEmpty()) {
82+
return $result;
83+
}
84+
7985
foreach ($result as $limit) {
80-
$limit->key = $limit->uniqueKey();
86+
if ($duplicates->contains($limit->key)) {
87+
$limit->key = $limit->fallbackKey();
88+
}
8189
}
8290

8391
return $result;

src/Illuminate/Cache/RateLimiting/Limit.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,12 @@ public function response(callable $callback)
144144
}
145145

146146
/**
147-
* Retrieve a unique key for the limit.
147+
* Retrieve a fallback key for the limit.
148148
*
149149
* @return string
150150
*/
151-
public function uniqueKey()
151+
public function fallbackKey()
152152
{
153-
if ($this->key !== '') {
154-
return $this->key;
155-
}
156-
157153
return "attempts:{$this->maxAttempts}:decay:{$this->decaySeconds}";
158154
}
159155
}

0 commit comments

Comments
 (0)