app/strategies/team_stats.rb
# Retrieve data from DB using the current seasons
# Use one single query to decrease db access
# Force team_id and seasons ids in the query before execute
# If non current seasons set no data will be retrieved
#
Retrieve data from DB using the current seasons
Use one single query to decrease db access
Force team_id and seasons ids in the query before execute
If non current seasons set no data will be retrieved
Retrieve data from DB using the current seasons Use one single query to decrease db access Force team_id and seasons ids in the query before execute If non current seasons set no data will be retrieved
def retrieve_data
    @stats = nil
    data_retrieve_query = "
      select st.short_name as federation_name,
        min(concat(ms.scheduled_date, ':', ms.meeting_id, ':', m.description, ':', ft.code)) as min_date,
        max(concat(ms.scheduled_date, ':', ms.meeting_id, ':', m.description, ':', ft.code)) as max_date,
        count(distinct ta.id) as affiliations_count,
        count(distinct ms.meeting_id) as meetings_count,
        0 as individual_meters,
        0 as individual_minutes,
        0 as individual_seconds,
        0 as individual_hundreds,
        0 as individual_disqualifications,
        max(mir.updated_at) as max_updated_at
      from meeting_individual_results mir
        join meeting_programs mp on mp.id = mir.meeting_program_id
        join meeting_events me on me.id = mp.meeting_event_id
        join meeting_sessions ms on ms.id = me.meeting_session_id
        join meetings m on m.id = ms.meeting_id
        join team_affiliations ta on ta.id = mir.team_affiliation_id
        join seasons s on s.id = ta.season_id
        join season_types st on st.id = s.season_type_id
        join federation_types ft on ft.id = st.federation_type_id
      where mir.team_id = VAR_TEAM_ID
      group by st.short_name;
    "
    data_retrieve_query.gsub!('VAR_TEAM_ID', @team.id.to_s)
    @stats = ActiveRecord::Base.connection.exec_query(data_retrieve_query)
  end
def retrieve_data @stats = nil data_retrieve_query = "
      select st.short_name as federation_name,
        min(concat(ms.scheduled_date, ':', ms.meeting_id, ':', m.description, ':', ft.code)) as min_date,
        max(concat(ms.scheduled_date, ':', ms.meeting_id, ':', m.description, ':', ft.code)) as max_date,
        count(distinct ta.id) as affiliations_count,
        count(distinct ms.meeting_id) as meetings_count,
        0 as individual_meters,
        0 as individual_minutes,
        0 as individual_seconds,
        0 as individual_hundreds,
        0 as individual_disqualifications,
        max(mir.updated_at) as max_updated_at
      from meeting_individual_results mir
        join meeting_programs mp on mp.id = mir.meeting_program_id
        join meeting_events me on me.id = mp.meeting_event_id
        join meeting_sessions ms on ms.id = me.meeting_session_id
        join meetings m on m.id = ms.meeting_id
        join team_affiliations ta on ta.id = mir.team_affiliation_id
        join seasons s on s.id = ta.season_id
        join season_types st on st.id = s.season_type_id
        join federation_types ft on ft.id = st.federation_type_id
      where mir.team_id = VAR_TEAM_ID
      group by st.short_name;
    " data_retrieve_query . gsub! ( 'VAR_TEAM_ID' , @team . id . to_s ) @stats = ActiveRecord :: Base . connection . exec_query ( data_retrieve_query ) end
Retrieve data from DB using the current seasons
Use one single query to decrease db access
Force team_id and seasons ids in the query before execute
If non current seasons set no data will be retrieved
Retrieve data from DB using the current seasons Use one single query to decrease db access Force team_id and seasons ids in the query before execute If non current seasons 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 swimmer_id will be forced in a second step # Prepare data retrieve query with swimmer as parameter # Retrieve data