<commit_before>class LocationsController < ApplicationController
  before_action :authenticate_user!, except: [:index, :show]
  before_action :set_location, except: [:index, :new, :create]
  include GraetzlChild

  def index
    @locations = @graetzl.locations
                          .approved
                          .includes(:address, :category)
                          .paginate_index(params[:page] || 1)
  end

  def new
    if request.get?
      @graetzl = Graetzl.find(params[:graetzl_id] || current_user.graetzl_id)
      @district = @graetzl.districts.first
      render :graetzl_form
    else
      @graetzl = Graetzl.find(params[:graetzl_id])
      @location = @graetzl.locations.build
      @location.build_contact
    end
  end

  def create
    @location = Location.new(location_params)
    if @location.save
      enqueue_and_redirect(root_url)
    else
      render :new
    end
  end

  def update
    if @location.update(location_params)
      redirect_to [@location.graetzl, @location]
    else
      render :edit
    end
  end

  def show
    if request.xhr?
      @new_content = paginate_show(@scope = params[:scope].to_sym)
    else
      if @location.pending?
        enqueue_and_redirect(:back)
      else
        verify_graetzl_child(@location)
        @upcoming = @location.meetings.basic.upcoming.includes(:graetzl).page(params[:upcoming]).per(2)
        @past = @location.meetings.basic.past.includes(:graetzl).page(params[:past]).per(2)
        @posts = @location.posts.includes(:graetzl, :images, :author).page(params[:page]).per(10)
      end
    end
  end

  def destroy
    if @location.users.include?(current_user) && @location.destroy
      flash[:notice] = 'Location entfernt'
    else
      flash[:error] = 'Nur Betreiber können Locations löschen'<commit_msg>optimize query for location_posts to include comments and images<commit_after>class LocationsController < ApplicationController
  before_action :authenticate_user!, except: [:index, :show]
  before_action :set_location, except: [:index, :new, :create]
  include GraetzlChild

  def index
    @locations = @graetzl.locations
                          .approved
                          .includes(:address, :category)
                          .paginate_index(params[:page] || 1)
  end

  def new
    if request.get?
      @graetzl = Graetzl.find(params[:graetzl_id] || current_user.graetzl_id)
      @district = @graetzl.districts.first
      render :graetzl_form
    else
      @graetzl = Graetzl.find(params[:graetzl_id])
      @location = @graetzl.locations.build
      @location.build_contact
    end
  end

  def create
    @location = Location.new(location_params)
    if @location.save
      enqueue_and_redirect(root_url)
    else
      render :new
    end
  end

  def update
    if @location.update(location_params)
      redirect_to [@location.graetzl, @location]
    else
      render :edit
    end
  end

  def show
    if request.xhr?
      @new_content = paginate_show(@scope = params[:scope].to_sym)
    else
      if @location.pending?
        enqueue_and_redirect(:back)
      else
        verify_graetzl_child(@location)
        @upcoming = @location.meetings.basic.upcoming.includes(:graetzl).page(params[:upcoming]).per(2)
        @past = @location.meetings.basic.past.includes(:graetzl).page(params[:past]).per(2)
        @posts = @location.posts.includes(:graetzl, :images, :author, comments: [:images, :user]).page(params[:page]).per(10)
      end
    end
  end

  def destroy
    if @location.users.include?(current_user) && @location.destroy
      flash[:notice] = 'Location entfernt'
    else
      flash[:error] = 'Nur Betreiber können Locations löschen'
{'fraction_non_alphanumeric': 0.10990502035278155, 'fraction_numerical': 0.0027137042062415195, 'mean_word_length': 2.8316008316008316, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6068890', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1148, 'n_words': 226}