mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 14:25:01 -05:00
15 lines
No EOL
565 B
CoffeeScript
15 lines
No EOL
565 B
CoffeeScript
settings = require("settings-sharelatex")
|
|
redis = require("redis-sharelatex")
|
|
rclient = redis.createClient(settings.redis.web)
|
|
redback = require("redback").use(rclient)
|
|
|
|
module.exports =
|
|
|
|
addCount: (opts, callback = (opts, shouldProcess)->)->
|
|
ratelimit = redback.createRateLimit(opts.endpointName)
|
|
ratelimit.addCount opts.subjectName, opts.timeInterval, (err, callCount)->
|
|
shouldProcess = callCount < opts.throttle
|
|
callback(err, shouldProcess)
|
|
|
|
clearRateLimit: (endpointName, subject, callback) ->
|
|
rclient.del "#{endpointName}:#{subject}", callback |