Skip to content

Commit

Permalink
Merge 4026a0f into edbcad3
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcgibbon authored Feb 8, 2023
2 parents edbcad3 + 4026a0f commit e919aba
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 35 deletions.
17 changes: 14 additions & 3 deletions lib/mini_profiler/profiler.rb → lib/mini_profiler.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# frozen_string_literal: true

require 'cgi'
require 'json'
require 'erb'

require 'mini_profiler/timer_struct'
require 'mini_profiler/storage'
require 'mini_profiler/config'
require 'mini_profiler/profiling_methods'
require 'mini_profiler/context'
require 'mini_profiler/client_settings'
require 'mini_profiler/gc_profiler'
require 'mini_profiler/snapshots_transporter'

module Rack
class MiniProfiler
Expand All @@ -27,11 +38,11 @@ def config
end

def resources_root
@resources_root ||= ::File.expand_path("../../html", __FILE__)
@resources_root ||= ::File.expand_path("../html", __FILE__)
end

def share_template
@share_template ||= ERB.new(::File.read(::File.expand_path("../html/share.html", ::File.dirname(__FILE__))))
@share_template ||= ERB.new(::File.read(::File.expand_path("html/share.html", ::File.dirname(__FILE__))))
end

def current
Expand Down Expand Up @@ -773,7 +784,7 @@ def get_profile_script(env)
end

# TODO : cache this snippet
script = ::File.read(::File.expand_path('../html/profile_handler.js', ::File.dirname(__FILE__)))
script = ::File.read(::File.expand_path('html/profile_handler.js', ::File.dirname(__FILE__)))
# replace the variables
settings.each do |k, v|
regex = Regexp.new("\\{#{k.to_s}\\}")
Expand Down
12 changes: 12 additions & 0 deletions lib/mini_profiler/storage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true


module Rack
class MiniProfiler
autoload(:AbstractStore, 'mini_profiler/storage/abstract_store')
autoload(:MemcacheStore, 'mini_profiler/storage/memcache_store')
autoload(:MemoryStore, 'mini_profiler/storage/memory_store')
autoload(:RedisStore, 'mini_profiler/storage/redis_store')
autoload(:FileStore, 'mini_profiler/storage/file_store')
end
end
2 changes: 2 additions & 0 deletions lib/mini_profiler/storage/file_store.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'securerandom'

module Rack
class MiniProfiler
class FileStore < AbstractStore
Expand Down
3 changes: 2 additions & 1 deletion lib/mini_profiler/storage/memcache_store.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'dalli'

module Rack
class MiniProfiler
class MemcacheStore < AbstractStore
Expand All @@ -8,7 +10,6 @@ class MemcacheStore < AbstractStore
MAX_RETRIES = 10

def initialize(args = nil)
require 'dalli' unless defined? Dalli
args ||= {}

@prefix = args[:prefix] || "MPMemcacheStore"
Expand Down
2 changes: 2 additions & 0 deletions lib/mini_profiler/storage/memory_store.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'securerandom'

module Rack
class MiniProfiler
class MemoryStore < AbstractStore
Expand Down
3 changes: 2 additions & 1 deletion lib/mini_profiler/storage/redis_store.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require 'digest'
require 'securerandom'
require 'redis'

module Rack
class MiniProfiler
Expand Down Expand Up @@ -270,7 +272,6 @@ def prefixed_id(id)

def redis
@redis_connection ||= begin
require 'redis' unless defined? Redis
Redis.new(@args)
end
end
Expand Down
8 changes: 8 additions & 0 deletions lib/mini_profiler/timer_struct.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require 'mini_profiler/timer_struct/base'
require 'mini_profiler/timer_struct/page'
require 'mini_profiler/timer_struct/sql'
require 'mini_profiler/timer_struct/custom'
require 'mini_profiler/timer_struct/client'
require 'mini_profiler/timer_struct/request'
2 changes: 2 additions & 0 deletions lib/mini_profiler/timer_struct/base.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'json'

module Rack
class MiniProfiler
module TimerStruct
Expand Down
2 changes: 2 additions & 0 deletions lib/mini_profiler/timer_struct/sql.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'erb'

module Rack
class MiniProfiler

Expand Down
26 changes: 1 addition & 25 deletions lib/rack-mini-profiler.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
# frozen_string_literal: true

require 'erb'
require 'json'
require 'timeout'
require 'thread'
require 'securerandom'

require 'mini_profiler/version'
require 'mini_profiler/asset_version'

require 'mini_profiler/timer_struct/base'
require 'mini_profiler/timer_struct/page'
require 'mini_profiler/timer_struct/sql'
require 'mini_profiler/timer_struct/custom'
require 'mini_profiler/timer_struct/client'
require 'mini_profiler/timer_struct/request'

require 'mini_profiler/storage/abstract_store'
require 'mini_profiler/storage/memcache_store'
require 'mini_profiler/storage/memory_store'
require 'mini_profiler/storage/redis_store'
require 'mini_profiler/storage/file_store'
require 'mini_profiler'

require 'mini_profiler/config'
require 'mini_profiler/profiling_methods'
require 'mini_profiler/context'
require 'mini_profiler/client_settings'
require 'mini_profiler/gc_profiler'
require 'mini_profiler/snapshots_transporter'
require 'mini_profiler/profiler'
require 'patches/sql_patches'
require 'patches/net_patches'

Expand Down
12 changes: 7 additions & 5 deletions spec/integration/railtie_methods_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# frozen_string_literal: true

require 'securerandom'
require 'rack/test'
require File.expand_path('../../../lib/mini_profiler_rails/railtie_methods', __FILE__)

def to_seconds(array)
array.map! { |n, s, f| [n, s / 1000.0, f / 1000.0] }
array
end

describe Rack::MiniProfilerRailsMethods do
def to_seconds(array)
array.map! { |n, s, f| [n, s / 1000.0, f / 1000.0] }
array
end


describe '#render_notification_handler' do
before do
allow(Process).to receive(:clock_gettime).and_return(0)
Expand Down

0 comments on commit e919aba

Please sign in to comment.