optimizations
This commit is contained in:
@@ -74,6 +74,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
$this->configureMessagingRateLimiters();
|
||||
$this->configureDownloadRateLimiter();
|
||||
$this->configureArtworkRateLimiters();
|
||||
$this->configureNovaCardRateLimiters();
|
||||
$this->configureReactionRateLimiters();
|
||||
$this->configureSocialRateLimiters();
|
||||
$this->configureSettingsRateLimiters();
|
||||
@@ -250,6 +251,23 @@ class AppServiceProvider extends ServiceProvider
|
||||
});
|
||||
}
|
||||
|
||||
private function configureNovaCardRateLimiters(): void
|
||||
{
|
||||
foreach (['drafts', 'autosave', 'publish', 'background_upload', 'render'] as $key) {
|
||||
RateLimiter::for('nova-cards-' . str_replace('_', '-', $key), function (Request $request) use ($key): array {
|
||||
$config = (array) config('nova_cards.rate_limits.' . $key, []);
|
||||
$perUser = max(1, (int) ($config['per_user'] ?? 30));
|
||||
$perIp = max(1, (int) ($config['per_ip'] ?? 60));
|
||||
$scope = 'nova-cards:' . $key . ':';
|
||||
|
||||
return [
|
||||
Limit::perMinute($perUser)->by($scope . 'user:' . ($request->user()?->id ?? 'guest')),
|
||||
Limit::perMinute($perIp)->by($scope . 'ip:' . $request->ip()),
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private function buildUploadLimits(Request $request, string $key): array
|
||||
{
|
||||
$config = (array) config('uploads.rate_limits.' . $key, []);
|
||||
@@ -384,6 +402,16 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
private function configureSocialRateLimiters(): void
|
||||
{
|
||||
RateLimiter::for('follow-write', function (Request $request): array {
|
||||
$userId = $request->user()?->id ?? 'guest';
|
||||
|
||||
return [
|
||||
Limit::perMinute(12)->by('follow-write:minute:user:' . $userId),
|
||||
Limit::perHour(120)->by('follow-write:hour:user:' . $userId),
|
||||
Limit::perMinute(24)->by('follow-write:minute:ip:' . $request->ip()),
|
||||
];
|
||||
});
|
||||
|
||||
RateLimiter::for('social-write', function (Request $request): array {
|
||||
$userId = $request->user()?->id ?? 'guest';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user