gitlab-org--gitlab-foss/lib/gitlab/gon_helper.rb
Paco Guzman b5fa56eb3f Unused got variable with very bad performance
In any case if just want the value which is always ‘gitlab’

require 'benchmark/ips'

Project.first # To load database things
GitlabIssueTrackerService.first # To load database things

Benchmark.ips do |x|
  x.config(:time => 5, :warmup => 2)

  x.report("current") do
    Project.new.default_issue_tracker.to_param
  end

  x.report("") do
    'gitlab'
  end

  x.compare!
end

Calculating -------------------------------------
             current     4.000  i/100ms
                        30.938k i/100ms
-------------------------------------------------
             current     47.298  (±10.6%) i/s -    232.000 
                          4.366M (±20.9%) i/s -     17.202M

Comparison:
                    :  4366456.0 i/s
             current:       47.3 i/s - 92318.26x slower
2016-06-28 17:01:37 +02:00

18 lines
744 B
Ruby

module Gitlab
module GonHelper
def add_gon_variables
gon.api_version = API::API.version
gon.default_avatar_url = URI::join(Gitlab.config.gitlab.url, ActionController::Base.helpers.image_path('no_avatar.png')).to_s
gon.max_file_size = current_application_settings.max_attachment_size
gon.relative_url_root = Gitlab.config.gitlab.relative_url_root
gon.shortcuts_path = help_shortcuts_path
gon.user_color_scheme = Gitlab::ColorSchemes.for_user(current_user).css_class
gon.award_menu_url = emojis_path
if current_user
gon.current_user_id = current_user.id
gon.api_token = current_user.private_token
end
end
end
end