@@ -46,6 +46,41 @@ export function expressRateLimiter(
4646 const redisClient = connect ( redisClientOptions ) ; // Default port is 6379 automatically
4747 const rateLimiter = setupRateLimiter ( rateLimiterAlgo , rateLimiterOptions , redisClient ) ;
4848
49+ // Sort the requests by timestamps to make sure we process in the correct order
50+ // We need to store the request, response and next object so that the correct one is used
51+ // the function we return accepts the unique request, response, next objects
52+ // it will store these and then process them in the order in which they were received.
53+ // We can do an event listener that waits for the previous request in the queue to be finished
54+ // store the middleware in closure
55+
56+ // Catch the request
57+ // add this to the queue
58+ // proccess the oldest request in the queue
59+ // check if the queue is empty => if not process the next request
60+ // otherwise return
61+ // process restarts when the next request comes in
62+
63+ // so r1, r2 come in
64+ // r1, and r2 get processed with thin same frame on call stack
65+ // r2 call is done once r2 is added to the queue
66+
67+ const requestsInProcess : { [ index : string ] : Request [ ] } = { } ;
68+
69+ // return a throttled middleware. Check every 100ms? make this a setting?
70+ // how do we make sure these get queued properly?
71+ // store the requests in an array when available grab the next request for a user
72+ /**
73+ * Request 1 comes in
74+ * Start handling request 1
75+ * In the meantime reqeust 2 comes in for the same suer
76+ * Finish handling request 1
77+ * check the queue for this user
78+ * if it's empty we're done
79+ * it it has a request handle the next one
80+ *
81+ * Not throttling on time just queueing requests.
82+ */
83+
4984 // return the rate limiting middleware
5085 return async (
5186 req : Request ,
@@ -70,6 +105,7 @@ export function expressRateLimiter(
70105 */
71106 // check for a proxied ip address before using the ip address on request
72107 const ip : string = req . ips ? req . ips [ 0 ] : req . ip ;
108+ // requestsInProcess[ip] = true;
73109
74110 // FIXME: this will only work with type complexity
75111 const queryAST = parse ( query ) ;
0 commit comments