app/strategies/meeting_reservations_summary.rb
# Retrieve data from DB using the current meeting and team
# Use one single query to decrease db access
# Force team and meeting ids in the query before execute
#
Retrieve data from DB using the current meeting and team
Use one single query to decrease db access
Force team and meeting ids in the query before execute
Retrieve data from DB using the current meeting and team Use one single query to decrease db access Force team and meeting ids in the query before execute
def retrieve_reservation_data
    @reservation_data_retrieved = nil
    data_retrieve_query = '
    select mr.swimmer_id, s.complete_name, ct.code as category_code,
      mer.meeting_event_id, mr.has_confirmed, et.code as event_code, me.is_out_of_race,
      mer.suggested_minutes as minutes, mer.suggested_seconds as seconds, mer.suggested_hundreds as hudreds,
      mer.updated_at, et.is_a_relay
    from meeting_reservations mr
     	join badges b on b.id = mr.badge_id
      join category_types ct on ct.id = b.category_type_id
      join swimmers s on s.id = mr.swimmer_id
    	join meeting_event_reservations mer on mer.meeting_id = mr.meeting_id and mer.badge_id = mr.badge_id
      join meeting_events me on me.id = mer.meeting_event_id
      join event_types et on et.id = me.event_type_id
    where mr.meeting_id = VAR_MEETING_ID
      and mr.team_id = VAR_TEAM_ID
    	and not mr.is_not_coming
      and mer.is_doing_this
    union
    select mr2.swimmer_id, s2.complete_name, ct2.code,
  	  mrr.meeting_event_id, mr2.has_confirmed, et2.code as event_code, me2.is_out_of_race,
      0 as minutes, 0 as seconds, 0 as hudreds,
      mrr.updated_at, et2.is_a_relay
    from meeting_reservations mr2
  	  join badges b2 on b2.id = mr2.badge_id
      join category_types ct2 on ct2.id = b2.category_type_id
      join swimmers s2 on s2.id = mr2.swimmer_id
  	  join meeting_relay_reservations mrr on mrr.meeting_id = mr2.meeting_id and mrr.badge_id = mr2.badge_id
      join meeting_events me2 on me2.id = mrr.meeting_event_id
      join event_types et2 on et2.id = me2.event_type_id
    where mr2.meeting_id = VAR_MEETING_ID
      and mr2.team_id = VAR_TEAM_ID
  	  and not mr2.is_not_coming
      and mrr.is_doing_this
    order by 2, 6;
    '
    data_retrieve_query.gsub!('VAR_MEETING_ID', @meeting.id.to_s)
    data_retrieve_query.gsub!('VAR_TEAM_ID', @team.id.to_s)
    @reservation_data_retrieved = ActiveRecord::Base.connection.exec_query(data_retrieve_query)
  end
def retrieve_reservation_data @reservation_data_retrieved = nil data_retrieve_query = '
    select mr.swimmer_id, s.complete_name, ct.code as category_code,
      mer.meeting_event_id, mr.has_confirmed, et.code as event_code, me.is_out_of_race,
      mer.suggested_minutes as minutes, mer.suggested_seconds as seconds, mer.suggested_hundreds as hudreds,
      mer.updated_at, et.is_a_relay
    from meeting_reservations mr
     	join badges b on b.id = mr.badge_id
      join category_types ct on ct.id = b.category_type_id
      join swimmers s on s.id = mr.swimmer_id
    	join meeting_event_reservations mer on mer.meeting_id = mr.meeting_id and mer.badge_id = mr.badge_id
      join meeting_events me on me.id = mer.meeting_event_id
      join event_types et on et.id = me.event_type_id
    where mr.meeting_id = VAR_MEETING_ID
      and mr.team_id = VAR_TEAM_ID
    	and not mr.is_not_coming
      and mer.is_doing_this
    union
    select mr2.swimmer_id, s2.complete_name, ct2.code,
  	  mrr.meeting_event_id, mr2.has_confirmed, et2.code as event_code, me2.is_out_of_race,
      0 as minutes, 0 as seconds, 0 as hudreds,
      mrr.updated_at, et2.is_a_relay
    from meeting_reservations mr2
  	  join badges b2 on b2.id = mr2.badge_id
      join category_types ct2 on ct2.id = b2.category_type_id
      join swimmers s2 on s2.id = mr2.swimmer_id
  	  join meeting_relay_reservations mrr on mrr.meeting_id = mr2.meeting_id and mrr.badge_id = mr2.badge_id
      join meeting_events me2 on me2.id = mrr.meeting_event_id
      join event_types et2 on et2.id = me2.event_type_id
    where mr2.meeting_id = VAR_MEETING_ID
      and mr2.team_id = VAR_TEAM_ID
  	  and not mr2.is_not_coming
      and mrr.is_doing_this
    order by 2, 6;
    ' data_retrieve_query . gsub! ( 'VAR_MEETING_ID' , @meeting . id . to_s ) data_retrieve_query . gsub! ( 'VAR_TEAM_ID' , @team . id . to_s ) @reservation_data_retrieved = ActiveRecord :: Base . connection . exec_query ( data_retrieve_query ) end
Retrieve data from DB using the current meeting and team
Use one single query to decrease db access
Force team and meeting ids in the query before execute
Retrieve data from DB using the current meeting and team Use one single query to decrease db access Force team and meeting ids in the query before execute
# Define query for data retrieve. # Query is defined in a way that should be easily execute in an SQL client # So meeting_id will be forced in a second step # Prepare data retrieve query with swimemr and date inteval as parameters # Retrieve data