debian-mirror-gitlab/lib/gitlab/anonymous_session.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
842 B
Ruby
Raw Normal View History

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
2022-03-02 08:16:31 +05:30
Gitlab::Redis::Sessions.with do |redis|
2022-01-26 12:08:38 +05:30
redis.pipelined do |pipeline|
pipeline.incr(session_lookup_name)
pipeline.expire(session_lookup_name, 24.hours)
2019-09-04 21:01:54 +05:30
end
end
end
2020-11-24 15:15:51 +05:30
def session_count
2022-03-02 08:16:31 +05:30
Gitlab::Redis::Sessions.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
2022-03-02 08:16:31 +05:30
Gitlab::Redis::Sessions.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
2022-01-26 12:08:38 +05:30
@session_lookup_name ||= "#{Gitlab::Redis::Sessions::IP_SESSIONS_LOOKUP_NAMESPACE}:#{remote_ip}"
2019-09-04 21:01:54 +05:30
end
end
end