{"issue":{"state":"open","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"milestone":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/c036cacc476ff03266fac8b91493c30d?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"c036cacc476ff03266fac8b91493c30d","url":"https://api.github.com/users/barmstrong","login":"barmstrong","id":25322},"labels":[],"assignee":null,"updated_at":"2011-11-16T04:31:52Z","comments":0,"closed_at":null,"url":"https://api.github.com/repos/vinova/voteable_mongo/issues/23","body":"Has anyone gotten rate limiting to work?\r\n\r\nIt doesn't look like there is a time stamp on any of the votes by default so a classic solution of \"how many votes did this user create in the last minute\" doesn't seem like it would work.\r\n\r\nI'll share one alternate solution that I just got working.  It keeps an timestamp on each user which starts out being 10 minutes ago (and can never be less than this).  It then increments the timestamp by 30 seconds for each action the user takes, and blocks additional actions if the timestamp is > Time.now\r\n\r\n\r\n    class User\r\n      ...\r\n      field :rate_limit, :type => Integer\r\n\r\n      ...\r\n      # checks AND updates rate limit\r\n      def over_rate_limit?\r\n        window = 10.minutes.ago.to_i\r\n        interval = 30.seconds.to_i\r\n    \r\n        return true if rate_limit.present? and rate_limit > Time.now.to_i\r\n        if rate_limit.nil? or rate_limit < window\r\n          self.rate_limit = window\r\n        end\r\n        self.rate_limit += interval\r\n        self.save!\r\n        false\r\n      end\r\n    end\r\n\r\nAny other solutions?","html_url":"https://github.com/vinova/voteable_mongo/issues/23","number":23,"title":"Rate limiting?","id":2252878,"created_at":"2011-11-16T04:31:52Z"},"action":"opened"}