Class: SpreeCmCommissioner::EventTicketAggregatorQuery
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::EventTicketAggregatorQuery
- Defined in:
- app/queries/spree_cm_commissioner/event_ticket_aggregator_query.rb
Instance Attribute Summary collapse
-
#refreshed ⇒ Object
readonly
Returns the value of attribute refreshed.
-
#taxon_id ⇒ Object
readonly
Returns the value of attribute taxon_id.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(taxon_id:, refreshed: false) ⇒ EventTicketAggregatorQuery
constructor
taxon_id:, refreshed: false.
- #product_aggregators ⇒ Object
Constructor Details
#initialize(taxon_id:, refreshed: false) ⇒ EventTicketAggregatorQuery
taxon_id:, refreshed: false
6 7 8 9 |
# File 'app/queries/spree_cm_commissioner/event_ticket_aggregator_query.rb', line 6 def initialize(taxon_id:, refreshed: false) @taxon_id = taxon_id @refreshed = refreshed end |
Instance Attribute Details
#refreshed ⇒ Object (readonly)
Returns the value of attribute refreshed.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/event_ticket_aggregator_query.rb', line 3 def refreshed @refreshed end |
#taxon_id ⇒ Object (readonly)
Returns the value of attribute taxon_id.
3 4 5 |
# File 'app/queries/spree_cm_commissioner/event_ticket_aggregator_query.rb', line 3 def taxon_id @taxon_id end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/queries/spree_cm_commissioner/event_ticket_aggregator_query.rb', line 11 def call cache_key = "event-ticket-aggregator-query-#{taxon_id}" Rails.cache.delete(cache_key) if refreshed value = Rails.cache.fetch(cache_key, expires_in: 5.minutes) do product_aggregators || [] end SpreeCmCommissioner::EventTicketAggregator.new( id: taxon_id, value: value ) end |
#product_aggregators ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/queries/spree_cm_commissioner/event_ticket_aggregator_query.rb', line 25 def product_aggregators select_fields = [ 'product_id', 'SUM(total_count) AS total_tickets', 'COUNT(*) AS total_items' ] Spree::Classification .select(select_fields) .joins(taxon: :parent) .where(parent: { id: taxon_id }) .group('product_id') .map do |record| record.slice( :product_id, :total_tickets, :total_items ) end end |