Sha256: 6c51ab67c9a7c755f6d49c14ca06318f898692287dbbe9b0517139210d9a924e

Contents?: true

Size: 1.87 KB

Versions: 19

Compression:

Stored size: 1.87 KB

Contents

module ActiveLdap
  module ActionController
    module LdapBenchmarking
      def self.included(base)
        base.class_eval do
          alias_method_chain :render_with_benchmark, :active_ldap
          if private_method_defined?(:view_runtime)
            alias_method_chain :view_runtime, :active_ldap
          else
            alias_method_chain :rendering_runtime, :active_ldap
          end
        end
      end

      protected
      def render_with_benchmark_with_active_ldap(*args, &block)
        if logger
          ldap_runtime_before_render = ActiveLdap::Base.reset_runtime
        end
        result = render_with_benchmark_without_active_ldap(*args, &block)
        if logger
          @ldap_runtime_before_render = ldap_runtime_before_render
          @ldap_runtime_after_render = ActiveLdap::Base.reset_runtime
          if defined?(@rendering_runtime)
            @rendering_runtime -= @ldap_runtime_after_render
          else
            @view_runtime -= @ldap_runtime_after_render
          end
        end
        result
      end

      private
      def rendering_runtime_with_active_ldap(runtime)
        result = rendering_runtime_without_active_ldap(runtime)
        ldap_runtime = ActiveLdap::Base.reset_runtime
        ldap_runtime += @ldap_runtime_before_render || 0
        ldap_runtime += @ldap_runtime_after_render || 0
        ldap_percentage = ldap_runtime * 100 / runtime
        result + (" | LDAP: %.5f (%d%%)" % [ldap_runtime, ldap_percentage])
      end

      def view_runtime_with_active_ldap
        result = view_runtime_without_active_ldap
        ldap_runtime = ActiveLdap::Base.reset_runtime
        @ldap_runtime_before_render ||= 0
        @ldap_runtime_after_render ||= 0
        ldap_runtime += @ldap_runtime_before_render
        ldap_runtime += @ldap_runtime_after_render
        result + (", LDAP: %.0f" % (ldap_runtime * 1000))
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
activeldap-3.2.3 lib/active_ldap/action_controller/ldap_benchmarking.rb
powerhome-activeldap-3.2.3 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-4.0.2 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-4.0.1 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-4.0.0 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-3.2.2 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-3.2.1 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-3.2.0 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-3.1.1 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-3.1.0 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-1.2.4 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-1.2.3 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap3-1.2.3 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-1.2.2 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-1.2.1 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-1.2.0 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-1.1.0 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-1.0.2 lib/active_ldap/action_controller/ldap_benchmarking.rb
activeldap-1.0.9 lib/active_ldap/action_controller/ldap_benchmarking.rb