2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
class AnonymousSession
|
2020-11-24 15:15:51 +05:30
|
|
|
def initialize(remote_ip)
|
2019-09-04 21:01:54 +05:30
|
|
|
@remote_ip = remote_ip
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def count_session_ip
|
2019-09-04 21:01:54 +05:30
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
|
|
|
redis.pipelined do
|
2020-11-24 15:15:51 +05:30
|
|
|
redis.incr(session_lookup_name)
|
2019-09-04 21:01:54 +05:30
|
|
|
redis.expire(session_lookup_name, 24.hours)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def session_count
|
2019-09-04 21:01:54 +05:30
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2020-11-24 15:15:51 +05:30
|
|
|
redis.get(session_lookup_name).to_i
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
def cleanup_session_per_ip_count
|
2019-09-04 21:01:54 +05:30
|
|
|
Gitlab::Redis::SharedState.with do |redis|
|
2020-11-24 15:15:51 +05:30
|
|
|
redis.del(session_lookup_name)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
attr_reader :remote_ip
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
def session_lookup_name
|
|
|
|
@session_lookup_name ||= "#{Gitlab::Redis::SharedState::IP_SESSIONS_LOOKUP_NAMESPACE}:#{remote_ip}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|