<commit_before>module Api
  module V2
    class SavedSearchesController < ApiController

      respond_to :json

      before_action :validate_content_type, only: [:create]
      before_action :validate_create, only: [:create]

      def index
        @user = current_user
        @saved_searches = @user.saved_searches.order("lower(name)")
        if @saved_searches.any?
          fresh_when(etag: @saved_searches, last_modified: @saved_searches.maximum(:updated_at))
        else
          @saved_searches = []
        end
      end

      def show
        @user = current_user
        saved_search = @user.saved_searches.where(id: params[:id]).first

        if saved_search.present?
          params[:query] = saved_search.query
          if params[:include_entries] && params[:include_entries] == "true"
            @entries = Entry.scoped_search(params, @user)
            links_header(@entries, 'api_v2_saved_search_url', saved_search.id)
          else
            params[:load] = false
            entries = Entry.scoped_search(params, @user)
            links_header(entries, 'api_v2_saved_search_url', saved_search.id)
            render json: entries.results.map {|entry| entry.id.to_i}.to_json
          end
        else
          status_forbidden
        end

      end

      def create
        @user = current_user
        @saved_search = @user.saved_searches.create(saved_search_params)
        render status: :created, location: api_v2_saved_search_url(@saved_search, format: :json)
      end

      def destroy
        @user = current_user<commit_msg>Check if out_of_bounds for saved_searches API.<commit_after>module Api
  module V2
    class SavedSearchesController < ApiController

      respond_to :json

      before_action :validate_content_type, only: [:create]
      before_action :validate_create, only: [:create]

      def index
        @user = current_user
        @saved_searches = @user.saved_searches.order("lower(name)")
        if @saved_searches.any?
          fresh_when(etag: @saved_searches, last_modified: @saved_searches.maximum(:updated_at))
        else
          @saved_searches = []
        end
      end

      def show
        @user = current_user
        saved_search = @user.saved_searches.where(id: params[:id]).first

        if saved_search.present?
          params[:query] = saved_search.query
          if params[:include_entries] && params[:include_entries] == "true"
            @entries = Entry.scoped_search(params, @user)
            if @entries.out_of_bounds?
              status_not_found
            else
              links_header(@entries, 'api_v2_saved_search_url', saved_search.id)
            end
          else
            params[:load] = false
            entries = Entry.scoped_search(params, @user)
            if entries.out_of_bounds?
              status_not_found
            else
              links_header(entries, 'api_v2_saved_search_url', saved_search.id)
              render json: entries.results.map {|entry| entry.id.to_i}.to_json
            end
          end
        else
          status_forbidden
        end

      end

      def create
        @user = current_user
        @saved_search = @user.saved_searches.create(saved_search_params)
        render status: :created, location: api_v2_saved_search_url(@saved_search, format: :json)
      end

      def destroy
        @user = current_user
{'fraction_non_alphanumeric': 0.08623744831659776, 'fraction_numerical': 0.002362669816893089, 'mean_word_length': 2.2787996127783154, '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': '3865485', 'n_tokens_mistral': 1013, 'n_tokens_neox': 1000, 'n_words': 196}