mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Lazily load profiler hooks
This commit is contained in:
+4
-1
@@ -41,6 +41,10 @@ module Liquid
|
|||||||
|
|
||||||
singleton_class.send(:attr_accessor, :cache_classes)
|
singleton_class.send(:attr_accessor, :cache_classes)
|
||||||
self.cache_classes = true
|
self.cache_classes = true
|
||||||
|
|
||||||
|
def self.load_profiler_hooks
|
||||||
|
require 'liquid/profiler/hooks'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "liquid/version"
|
require "liquid/version"
|
||||||
@@ -75,4 +79,3 @@ require 'liquid/token'
|
|||||||
Dir[File.dirname(__FILE__) + '/liquid/tags/*.rb'].each { |f| require f }
|
Dir[File.dirname(__FILE__) + '/liquid/tags/*.rb'].each { |f| require f }
|
||||||
|
|
||||||
require 'liquid/profiler'
|
require 'liquid/profiler'
|
||||||
require 'liquid/profiler/hooks'
|
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ module Liquid
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.hooks_loaded
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
def self.profile_token_render(token)
|
def self.profile_token_render(token)
|
||||||
if Profiler.current_profile && token.respond_to?(:render)
|
if Profiler.current_profile && token.respond_to?(:render)
|
||||||
Profiler.current_profile.start_token(token)
|
Profiler.current_profile.start_token(token)
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
module Liquid
|
module Liquid
|
||||||
|
class Profiler
|
||||||
|
def self.hooks_loaded
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class BlockBody
|
class BlockBody
|
||||||
def render_token_with_profiling(token, context)
|
def render_token_with_profiling(token, context)
|
||||||
Profiler.profile_token_render(token) do
|
Profiler.profile_token_render(token) do
|
||||||
|
|||||||
@@ -250,6 +250,8 @@ module Liquid
|
|||||||
|
|
||||||
def with_profiling
|
def with_profiling
|
||||||
if @profiling && !@options[:included]
|
if @profiling && !@options[:included]
|
||||||
|
Liquid.load_profiler_hooks unless Profiler.hooks_loaded
|
||||||
|
|
||||||
@profiler = Profiler.new
|
@profiler = Profiler.new
|
||||||
@profiler.start
|
@profiler.start
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user