app/strategies/meeting_schedule.rb
# Retrieve schedule data from DB using the current meeting
# Use one single query to decrease db access
# Force meeting id in the query before execute
#
Retrieve schedule data from DB using the current meeting
Use one single query to decrease db access
Force meeting id in the query before execute
Retrieve schedule data from DB using the current meeting Use one single query to decrease db access Force meeting id in the query before execute
def retrieve_schedule_data
    @schedule_data_retrieved = nil
    data_retrieve_query = '
    select ms.id as meeting_session_id,
    	ms.session_order, ms.scheduled_date, substr(ms.begin_time, 1, 5) as begin_time, substr(ms.warm_up_time, 1, 5) as warm_up_time, ms.notes as session_notes,
	    sp.id as swimming_pool_id, sp.lanes_number, sp.name as pool_name, sp.address as pool_address, c.name as city, sp.maps_uri, pt.code as pool_type,
      me.id as meeting_event_id, me.event_order, et.code as event_code, et.is_a_relay,
      me.is_out_of_race, me.has_separate_gender_start_list as has_separate_gender, me.has_separate_category_start_list as has_separate_categories, me.notes as event_notes
    from meeting_sessions ms
	    join swimming_pools sp on sp.id = ms.swimming_pool_id
      join pool_types pt on pt.id = sp.pool_type_id
      join meeting_events me on me.meeting_session_id = ms.id
      join event_types et on et.id = me.event_type_id
      join cities c on c.id = sp.city_id
    where ms.meeting_id = VAR_MEETING_ID
    order by ms.session_order, me.event_order;
    '
    data_retrieve_query.gsub!('VAR_MEETING_ID', @meeting.id.to_s)
    @schedule_data_retrieved = ActiveRecord::Base.connection.exec_query(data_retrieve_query)
  end
def retrieve_schedule_data @schedule_data_retrieved = nil data_retrieve_query = '
    select ms.id as meeting_session_id,
    	ms.session_order, ms.scheduled_date, substr(ms.begin_time, 1, 5) as begin_time, substr(ms.warm_up_time, 1, 5) as warm_up_time, ms.notes as session_notes,
	    sp.id as swimming_pool_id, sp.lanes_number, sp.name as pool_name, sp.address as pool_address, c.name as city, sp.maps_uri, pt.code as pool_type,
      me.id as meeting_event_id, me.event_order, et.code as event_code, et.is_a_relay,
      me.is_out_of_race, me.has_separate_gender_start_list as has_separate_gender, me.has_separate_category_start_list as has_separate_categories, me.notes as event_notes
    from meeting_sessions ms
	    join swimming_pools sp on sp.id = ms.swimming_pool_id
      join pool_types pt on pt.id = sp.pool_type_id
      join meeting_events me on me.meeting_session_id = ms.id
      join event_types et on et.id = me.event_type_id
      join cities c on c.id = sp.city_id
    where ms.meeting_id = VAR_MEETING_ID
    order by ms.session_order, me.event_order;
    ' data_retrieve_query . gsub! ( 'VAR_MEETING_ID' , @meeting . id . to_s ) @schedule_data_retrieved = ActiveRecord :: Base . connection . exec_query ( data_retrieve_query ) end
Retrieve schedule data from DB using the current meeting
Use one single query to decrease db access
Force meeting id in the query before execute
Retrieve schedule data from DB using the current meeting Use one single query to decrease db access Force meeting id 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