app/strategies/meeting_results.rb
# Retrieve data from DB using the current meeting
# Use one single query to decrease db access
# Force meeting_id in the query before execute
# If non current meeting set no data will be retrieved
#
Retrieve data from DB using the current meeting
Use one single query to decrease db access
Force meeting_id in the query before execute
If non current meeting set no data will be retrieved
Retrieve data from DB using the current meeting Use one single query to decrease db access Force meeting_id in the query before execute If non current meeting set no data will be retrieved
def retrieve_data_by_query
    @data_retrieved = nil
    data_retrieve_query = "
    select ms.session_order,
      me.event_order,
      et.code as event_code,
      ht.code as heat_type,
      me.is_out_of_race,
      gt.code as gender_code,
      ct.age_begin,
      ct.code as category_code,
    	mir.rank,
      mir.is_disqualified,
      mir.minutes,
      mir.seconds,
      mir.hundreds,
      mir.is_personal_best,
      mir.reaction_time,
      mir.standard_points,
      mir.meeting_individual_points,
      mir.goggle_cup_points,
      mir.team_points,
      s.complete_name,
      s.year_of_birth,
      ta.name as team_name,
      mir.updated_at,
      mir.team_id,
      mir.swimmer_id,
      mp.meeting_event_id,
      mir.meeting_program_id
    from meeting_sessions ms
    	join meeting_events me on me.meeting_session_id = ms.id
      join heat_types ht on ht.id = me.heat_type_id
    	join meeting_programs mp on mp.meeting_event_id = me.id
        join meeting_individual_results mir on mir.meeting_program_id = mp.id
        join event_types et on et.id = me.event_type_id
        join gender_types gt on gt.id = mp.gender_type_id
        join category_types ct on ct.id = mp.category_type_id
        join team_affiliations ta on ta.id = mir.team_affiliation_id
        join swimmers s on s.id = mir.swimmer_id
    where ms.meeting_id = VAR_MEETING_ID
    order by ms.session_order, me.event_order, ht.code, gt.code, ct.age_begin, mir.is_disqualified, mir.rank
    "
    data_retrieve_query.gsub!('VAR_MEETING_ID', @meeting.id.to_s)
    @data_retrieved = ActiveRecord::Base.connection.exec_query(data_retrieve_query)
  end
def retrieve_data_by_query @data_retrieved = nil data_retrieve_query = "
    select ms.session_order,
      me.event_order,
      et.code as event_code,
      ht.code as heat_type,
      me.is_out_of_race,
      gt.code as gender_code,
      ct.age_begin,
      ct.code as category_code,
    	mir.rank,
      mir.is_disqualified,
      mir.minutes,
      mir.seconds,
      mir.hundreds,
      mir.is_personal_best,
      mir.reaction_time,
      mir.standard_points,
      mir.meeting_individual_points,
      mir.goggle_cup_points,
      mir.team_points,
      s.complete_name,
      s.year_of_birth,
      ta.name as team_name,
      mir.updated_at,
      mir.team_id,
      mir.swimmer_id,
      mp.meeting_event_id,
      mir.meeting_program_id
    from meeting_sessions ms
    	join meeting_events me on me.meeting_session_id = ms.id
      join heat_types ht on ht.id = me.heat_type_id
    	join meeting_programs mp on mp.meeting_event_id = me.id
        join meeting_individual_results mir on mir.meeting_program_id = mp.id
        join event_types et on et.id = me.event_type_id
        join gender_types gt on gt.id = mp.gender_type_id
        join category_types ct on ct.id = mp.category_type_id
        join team_affiliations ta on ta.id = mir.team_affiliation_id
        join swimmers s on s.id = mir.swimmer_id
    where ms.meeting_id = VAR_MEETING_ID
    order by ms.session_order, me.event_order, ht.code, gt.code, ct.age_begin, mir.is_disqualified, mir.rank
    " data_retrieve_query . gsub! ( 'VAR_MEETING_ID' , @meeting . id . to_s ) @data_retrieved = ActiveRecord :: Base . connection . exec_query ( data_retrieve_query ) end
Retrieve data from DB using the current meeting
Use one single query to decrease db access
Force meeting_id in the query before execute
If non current meeting set no data will be retrieved
Retrieve data from DB using the current meeting Use one single query to decrease db access Force meeting_id in the query before execute If non current meeting set no data will be retrieved
# 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