Module: Inventory::InvCheckerHungryHubService::BulkData
- Extended by:
- ActiveSupport::Concern
- Includes:
- Constants
- Included in:
- Inventory::InvCheckerHungryHubService
- Defined in:
- app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb
Instance Method Summary collapse
- #find_durations(date, start_times, slug = nil) ⇒ Object
-
#res_durations_is_enough?(date, start_times, slug = nil) ⇒ Boolean
private
this is a private method, don't call this method directly.
-
#seat_lefts(date, start_times, slug = nil) ⇒ Object
main idea to find the availability is by checking: Scenario: restaurant has packages 1.
- #set_durations(date, start_times, slug = nil) ⇒ Object
- #set_res_durations_is_enough(date, start_times, slug = nil) ⇒ Object
- #set_seat_lefts(date, start_times, slug = nil) ⇒ Object
- #set_slugs_by_start_times(date, start_times) ⇒ Object
-
#slugs_by_start_times(date, start_times) ⇒ Hash
> {“slug1”, “slug2”>, “00:15”=>#<Set: {}>}.
Instance Method Details
#find_durations(date, start_times, slug = nil) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb', line 56 def find_durations(date, start_times, slug = nil) # we only need to update durations data if there is a change in the restaurant or package level redis_cache_key = durations_cache_key(date, slug) data_store.fetch_mapped_hmget(redis_cache_key, start_times, default_value: 0) do |missing_data| missing_start_times = missing_data.keys missing_data.merge!(calc_durations(date, missing_start_times, slug)) end end |
#res_durations_is_enough?(date, start_times, slug = nil) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
this is a private method, don't call this method directly
102 103 104 105 106 107 108 109 |
# File 'app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb', line 102 def res_durations_is_enough?(date, start_times, slug = nil) # we only need to update this cache if there is a change in the restaurant or package level redis_key = res_durations_is_enough_cache_key(date, slug) data_store.fetch_mapped_hmget(redis_key, start_times, default_value: false) do |missing_data| missing_start_times = missing_data.keys missing_data.merge!(calc_res_durations_is_enough(date, missing_start_times, slug)) end end |
#seat_lefts(date, start_times, slug = nil) ⇒ Object
main idea to find the availability is by checking: Scenario: restaurant has packages
-
find available slugs by start times #slugs_by_start_times
-
check duration is enough for each slug #res_durations_is_enough?
-
find seat lefts for each slug #seat_lefts
the valid start times are the ones who has seat lefts > 0
Scenario: restaurant does not have packages
-
check duration is enough for each slug #res_durations_is_enough?
-
find seat lefts for each slug #seat_lefts
36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb', line 36 def seat_lefts(date, start_times, slug = nil) # seat left data is affected by reservation, so we have to refresh the cache if there is any change in the reservation level # it is also affected when there is an update on inventory on restaurant or package level # so we need to revise the value of the cache key when there is a change in the Inventory, Reservation or Package level redis_cache_key = seat_lefts_cache_key(date, slug) data_store.fetch_mapped_hmget(redis_cache_key, start_times, default_value: 0) do |missing_data| missing_start_times = missing_data.keys missing_data.merge!(calc_seat_lefts(date, missing_start_times, slug)) end end |
#set_durations(date, start_times, slug = nil) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb', line 65 def set_durations(date, start_times, slug = nil) redis_cache_key = durations_cache_key(date, slug) data_store.mapped_hmset(redis_cache_key, start_times, date) do |data| computed = calc_durations(date, start_times, slug) # OPTIMIZATION: Only store non-zero durations to save memory data.merge!(computed.select { |_k, v| v.to_i != 0 }) end end |
#set_res_durations_is_enough(date, start_times, slug = nil) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb', line 111 def set_res_durations_is_enough(date, start_times, slug = nil) redis_key = res_durations_is_enough_cache_key(date, slug) data_store.mapped_hmset(redis_key, start_times, date) do |data| computed = calc_res_durations_is_enough(date, start_times, slug) # OPTIMIZATION: Only store true values, false is default data.merge!(computed.select { |_k, v| v == true }) end end |
#set_seat_lefts(date, start_times, slug = nil) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb', line 47 def set_seat_lefts(date, start_times, slug = nil) redis_cache_key = seat_lefts_cache_key(date, slug) data_store.mapped_hmset(redis_cache_key, start_times, date) do |data| computed = calc_seat_lefts(date, start_times, slug) # OPTIMIZATION: Only store non-zero values to save memory data.merge!(computed.select { |_k, v| v != 0 }) end end |
#set_slugs_by_start_times(date, start_times) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb', line 91 def set_slugs_by_start_times(date, start_times) redis_key = slugs_by_start_times_cache_key(date) data_store.mapped_hmset(redis_key, start_times, date) do |data| computed = calc_slugs_by_start_times(date, start_times) # OPTIMIZATION: Only store non-empty Sets to save memory data.merge!(computed.select { |_k, v| v.present? }) end end |
#slugs_by_start_times(date, start_times) ⇒ Hash
> {“slug1”, “slug2”>,
"00:15"=>#<Set: {}>}
80 81 82 83 84 85 86 87 88 89 |
# File 'app/services/inventory/inv_checker_hungry_hub_service/bulk_data.rb', line 80 def slugs_by_start_times(date, start_times) # this cache only need to be updated when there is a change in the package level # the data is tied to specific start_time, not specific restaurant_package # so that's why use `restaurant_scope` scope redis_key = slugs_by_start_times_cache_key(date) data_store.fetch_mapped_hmget(redis_key, start_times, default_value: Set.new) do |missing_data| missing_start_times = missing_data.keys missing_data.merge!(calc_slugs_by_start_times(date, missing_start_times)) end end |