From bd86340865fd190fad847153444da539bac45bc4 Mon Sep 17 00:00:00 2001 From: saturn Date: Wed, 15 Mar 2023 20:47:38 -0500 Subject: [PATCH] Skip rate limiting for logged in users. --- lw2.lisp | 3 ++- src/backend.lisp | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lw2.lisp b/lw2.lisp index fdb72e18..5cb17d0a 100644 --- a/lw2.lisp +++ b/lw2.lisp @@ -812,7 +812,8 @@ signaled condition to *HTML-OUTPUT*." auth-token (cache-get "auth-token-to-userid" auth-token) (cache-get "auth-token-to-username" auth-token))))) - (let ((*current-user-slug* (and *current-userid* (get-user-slug *current-userid*)))) + (let ((*current-user-slug* (and *current-userid* (get-user-slug *current-userid*))) + (*enable-rate-limit* (if *current-userid* nil *enable-rate-limit*))) (funcall fn))))) (defmethod call-with-site-context ((site ignore-list-site) (request (eql t)) fn) diff --git a/src/backend.lisp b/src/backend.lisp index 647bff78..8a94a9c1 100644 --- a/src/backend.lisp +++ b/src/backend.lisp @@ -9,6 +9,7 @@ #:*revalidate-default* #:*force-revalidate-default* #:*messages-index-fields* #:*notifications-base-terms* + #:*enable-rate-limit* #:start-background-loader #:stop-background-loader #:background-loader-running-p #:call-with-http-response #:forwarded-header #:backend-request-headers @@ -212,6 +213,8 @@ do (setf res (+ n (ash res 8))) finally (return res)))) +(defvar *enable-rate-limit* t) + (defparameter *rate-limit-cost-factor* 1) (sb-ext:defglobal *global-token-bucket* (make-token-bucket :rate 3 :burst 180)) @@ -221,7 +224,8 @@ (error "Rate limit exceeded. Try again later."))) (defun call-with-http-response (fn uri-string &rest args &key &allow-other-keys) - (check-rate-limit) + (when *enable-rate-limit* + (check-rate-limit)) (let* ((uri (quri:uri uri-string)) (uri-dest (concatenate 'string (quri:uri-host uri) ":" (format nil "~d" (quri:uri-port uri)))) (stream (connection-pop uri-dest))) -- 2.11.4.GIT