Class: FastExists::MultiTenant::Strategies::SharedStrategy
- Inherits:
-
BaseStrategy
- Object
- BaseStrategy
- FastExists::MultiTenant::Strategies::SharedStrategy
- Defined in:
- lib/fast_exists/multi_tenant/strategies/shared_strategy.rb
Instance Attribute Summary collapse
-
#pools ⇒ Object
readonly
Returns the value of attribute pools.
Attributes inherited from BaseStrategy
Instance Method Summary collapse
- #add(tenant_id, attribute, value) ⇒ Object
- #classify_tenant(_tenant_id, record_count) ⇒ Object
- #contains?(tenant_id, attribute, value) ⇒ Boolean
-
#initialize(options = {}) ⇒ SharedStrategy
constructor
A new instance of SharedStrategy.
- #stats ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SharedStrategy
Returns a new instance of SharedStrategy.
9 10 11 12 13 14 15 16 |
# File 'lib/fast_exists/multi_tenant/strategies/shared_strategy.rb', line 9 def initialize( = {}) super @pools = { small: FastExists::MultiTenant::Pool.new(name: "small", expected_elements: 500_000), medium: FastExists::MultiTenant::Pool.new(name: "medium", expected_elements: 2_000_000), large: FastExists::MultiTenant::Pool.new(name: "large", expected_elements: 10_000_000) } end |
Instance Attribute Details
#pools ⇒ Object (readonly)
Returns the value of attribute pools.
7 8 9 |
# File 'lib/fast_exists/multi_tenant/strategies/shared_strategy.rb', line 7 def pools @pools end |
Instance Method Details
#add(tenant_id, attribute, value) ⇒ Object
18 19 20 21 |
# File 'lib/fast_exists/multi_tenant/strategies/shared_strategy.rb', line 18 def add(tenant_id, attribute, value) pool = pool_for(tenant_id) pool.add(tenant_id, attribute, value) end |
#classify_tenant(_tenant_id, record_count) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fast_exists/multi_tenant/strategies/shared_strategy.rb', line 28 def classify_tenant(_tenant_id, record_count) case record_count when 0..100_000 then :small when 100_001..1_000_000 then :medium else :large end end |
#contains?(tenant_id, attribute, value) ⇒ Boolean
23 24 25 26 |
# File 'lib/fast_exists/multi_tenant/strategies/shared_strategy.rb', line 23 def contains?(tenant_id, attribute, value) pool = pool_for(tenant_id) pool.contains?(tenant_id, attribute, value) end |
#stats ⇒ Object
36 37 38 39 40 41 |
# File 'lib/fast_exists/multi_tenant/strategies/shared_strategy.rb', line 36 def stats { strategy: :shared, pools: @pools.transform_values(&:stats) } end |