module Concerns
  module Rankable
    extend ActiveSupport::Concern

    included do |base|
      class_attribute :ranking_key
      class_attribute :minimum_rankable_star
    end

    def rank
      Redis.current.zcount(ranking_key, "(#{stargazers_count}", '+inf') + 1
    rescue Redis::CannotConnectError
      super
    end

    def update_ranking
      if stargazers_count > 0
        Redis.current.zadd(ranking_key, stargazers_count, id)
      else
        Redis.current.zrem(ranking_key, id)
      end
    end
  end
end

module Concerns
  module Rankable
    extend ActiveSupport::Concern

    included do |base|
      class_attribute :ranking_key
      class_attribute :minimum_rankable_star
    end

    def rank
      super
      # Redis.current.zcount(ranking_key, "(#{stargazers_count}", '+inf') + 1
    rescue Redis::CannotConnectError
      super
    end

    def update_ranking
      if stargazers_count > 0
        Redis.current.zadd(ranking_key, stargazers_count, id)
      else
        Redis.current.zrem(ranking_key, id)
      end
    end
  end
end

Revert "Use redis rank again"
Revert "Use redis rank again"

This reverts commit 4cb5891292dc9bcca1b8498bfd479b49b044e036.
