<commit_before>class TeamsController < ApplicationController

  def show
    
  end
  
  def index
    sort = params[:sort] || session[:sort] || 'default'
    case sort
    when 'default'
      ordering, @num_members_header = {:users_count => :desc}, 'hilite'
    when 'users_count'
      if session[:ordering][:num_members] == :desc
        ordering,@num_members_header = {:users_count => :asc}, 'hilite'
      else
        ordering,@num_members_header = {:users_count => :desc}, 'hilite'
      end
    when 'pending_requests'
      if session[:ordering][:pending_requests] == :desc
        ordering,@pending_requests_header = {:pending_requests => :asc}, 'hilite'
      else
        ordering,@pending_requests_header = {:pending_requests => :desc}, 'hilite'
      end
    end
    @majors = Team.all_declared
    @selected_majors = params[:declared] || session[:declared] || {}
    
    if @selected_majors == {}
      @selected_majors = Hash[@majors.map {|major| [major, major]}]
    end
    
    if params[:sort] != session[:sort] or params[:declared] != session[:declared]
      session[:sort] = sort
      session[:declared] = @selected_majors
      redirect_to :sort => sort, :declared => @selected_majors and return
    end
    
    session[:ordering] = ordering
    # @teams = Team.where(declared: @selected_majors.keys).order(ordering)
    @teams = Team.order(ordering)
  end
  
  
  def update
  
  end
  
  
 end<commit_msg>Fixed bugs in legacy code that caused team.users counter_cache to update incorrectly. Reordered code in users_controller start_team and join_team that caused teams to increment by 2 when users joined. Deleted 1 line of code in user.leave_team that caused teams to decrement by 2 when a user leaved the team.<commit_after>class TeamsController < ApplicationController

  def show
    
  end


  def index
    sort = params[:sort] || session[:sort] || 'default'
    case sort
    when 'default'
      ordering, @num_members_header = {:users_count => :desc}, 'hilite'
    when 'users_count'
      if session[:ordering][:num_members] == :desc
        ordering,@num_members_header = {:users_count => :asc}, 'hilite'
      else
        ordering,@num_members_header = {:users_count => :desc}, 'hilite'
      end
    when 'pending_requests'
      if session[:ordering][:pending_requests] == :desc
        ordering,@pending_requests_header = {:pending_requests => :asc}, 'hilite'
      else
        ordering,@pending_requests_header = {:pending_requests => :desc}, 'hilite'
      end
    end
    @majors = Team.all_declared
    @selected_majors = params[:declared] || session[:declared] || {}
    
    if @selected_majors == {}
      @selected_majors = Hash[@majors.map {|major| [major, major]}]
    end
    
    if params[:sort] != session[:sort] or params[:declared] != session[:declared]
      session[:sort] = sort
      session[:declared] = @selected_majors
      redirect_to :sort => sort, :declared => @selected_majors and return
    end
    
    session[:ordering] = ordering
    # @teams = Team.where(declared: @selected_majors.keys).order(ordering)
    @teams = Team.order(ordering)
  end
  
  
  def update
  
  end
  
  
 end
{'fraction_non_alphanumeric': 0.12171988618400253, 'fraction_numerical': 0.0009484666455896301, 'mean_word_length': 3.2699055330634277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4992843', 'n_tokens_mistral': 1013, 'n_tokens_neox': 982, 'n_words': 237}