services/api/app/controllers/application_controller.rb
# limit_database_read ensures @objects (which must be an
# ActiveRelation) does not return too many results to fit in memory,
# by previewing the results and calling @objects.limit() if
# necessary.
limit_database_read ensures @objects (which must be an
ActiveRelation) does not return too many results to fit in memory,
by previewing the results and calling @objects.limit() if
necessary.
limit_database_read ensures @objects ( which must be an ActiveRelation ) does not return too many results to fit in memory by previewing the results and calling @objects . limit () if necessary .
def limit_database_read(model_class:)
    return if @limit == 0 || @limit == 1
    model_class ||= self.model_class
    limit_columns = model_class.limit_index_columns_read
    limit_columns &= model_class.columns_for_attributes(@select) if @select
    return if limit_columns.empty?
    model_class.transaction do
      limit_query = @objects.
        except(:select, :distinct).
        select("(%s) as read_length" %
               limit_columns.map { |s| "octet_length(#{model_class.table_name}.#{s})" }.join(" + "))
      new_limit = 0
      read_total = 0
      limit_query.each do |record|
        new_limit += 1
        read_total += record.read_length.to_i
        if read_total >= Rails.configuration.API.MaxIndexDatabaseRead
          new_limit -= 1 if new_limit > 1
          @limit = new_limit
          break
        elsif new_limit >= @limit
          break
        end
      end
      @objects = @objects.limit(@limit)
      @objects.each { |_| break }
    end
  end
def limit_database_read ( model_class : ) return if @limit == 0 || @limit == 1 model_class ||= self . model_class limit_columns = model_class . limit_index_columns_read limit_columns &= model_class . columns_for_attributes ( @select ) if @select return if limit_columns . empty? model_class . transaction do limit_query = @objects . except ( :select , :distinct ) . select ( "(%s) as read_length" % limit_columns . map { | s | "octet_length(#{model_class.table_name}.#{s})" } . join ( " + " ) ) new_limit = 0 read_total = 0 limit_query . each do | record | new_limit += 1 read_total += record . read_length . to_i if read_total >= Rails . configuration . API . MaxIndexDatabaseRead new_limit -= 1 if new_limit > 1 @limit = new_limit break elsif new_limit >= @limit break end end @objects = @objects . limit ( @limit ) @objects . each { | _ | break } end end
limit_database_read ensures @objects (which must be an
ActiveRelation) does not return too many results to fit in memory,
by previewing the results and calling @objects.limit() if
necessary.
limit_database_read ensures @objects ( which must be an ActiveRelation ) does not return too many results to fit in memory by previewing the results and calling @objects . limit () if necessary .
# Force @objects to run its query inside this transaction.
model_class