2019-07-18 04:27:02 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
class AnonymousSession
|
2020-08-28 05:10:32 -04:00
|
|
|
def initialize(remote_ip)
|
2019-07-18 04:27:02 -04:00
|
|
|
@remote_ip = remote_ip
|
|
|
|
end
|
|
|
|
|
2020-08-28 05:10:32 -04:00
|
|
|
def count_session_ip
|
2022-01-13 01:14:35 -05:00
|
|
|
Gitlab::Redis::Sessions.with do |redis|
|
2021-12-01 13:15:19 -05:00
|
|
|
redis.pipelined do |pipeline|
|
|
|
|
pipeline.incr(session_lookup_name)
|
|
|
|
pipeline.expire(session_lookup_name, 24.hours)
|
2019-07-18 04:27:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-28 05:10:32 -04:00
|
|
|
def session_count
|
2022-01-13 01:14:35 -05:00
|
|
|
Gitlab::Redis::Sessions.with do |redis|
|
2020-08-28 05:10:32 -04:00
|
|
|
redis.get(session_lookup_name).to_i
|
2019-07-18 04:27:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-28 05:10:32 -04:00
|
|
|
def cleanup_session_per_ip_count
|
2022-01-13 01:14:35 -05:00
|
|
|
Gitlab::Redis::Sessions.with do |redis|
|
2020-08-28 05:10:32 -04:00
|
|
|
redis.del(session_lookup_name)
|
2019-07-18 04:27:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-08-28 05:10:32 -04:00
|
|
|
attr_reader :remote_ip
|
2019-07-18 04:27:02 -04:00
|
|
|
|
|
|
|
def session_lookup_name
|
2021-11-24 13:14:31 -05:00
|
|
|
@session_lookup_name ||= "#{Gitlab::Redis::Sessions::IP_SESSIONS_LOOKUP_NAMESPACE}:#{remote_ip}"
|
2019-07-18 04:27:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|