Class: Kameleoon::Managers::Tracking::LockVisitorTrackingRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/managers/tracking/visitor_tracking_registry.rb

Constant Summary collapse

LIMITED_EXTRACTION_THRESHOLD_COEFFICIENT =
2
REMOVAL_FACTOR =
0.8

Instance Method Summary collapse

Constructor Details

#initialize(visitor_manager, storage_limit = 1_000_000, extraction_limit = 20_000) ⇒ LockVisitorTrackingRegistry

Returns a new instance of LockVisitorTrackingRegistry.



12
13
14
15
16
17
18
# File 'lib/kameleoon/managers/tracking/visitor_tracking_registry.rb', line 12

def initialize(visitor_manager, storage_limit = 1_000_000, extraction_limit = 20_000)
  @visitor_manager = visitor_manager
  @storage_limit = storage_limit
  @extraction_limit = extraction_limit
  @visitors = Set.new
  @mutex = Mutex.new
end

Instance Method Details

#add(visitor_code) ⇒ Object



20
21
22
# File 'lib/kameleoon/managers/tracking/visitor_tracking_registry.rb', line 20

def add(visitor_code)
  @mutex.synchronize { @visitors.add(visitor_code) }
end

#add_all(visitor_codes) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/kameleoon/managers/tracking/visitor_tracking_registry.rb', line 24

def add_all(visitor_codes)
  @mutex.synchronize do
    @visitors.merge(visitor_codes)
    if @visitors.size > @storage_limit
      erase_nonexistent_visitors
      erase_to_storage_limit
    end
  end
end

#extractObject



34
35
36
# File 'lib/kameleoon/managers/tracking/visitor_tracking_registry.rb', line 34

def extract
  should_extract_all_be_used ? extract_all : extract_limited
end