Sha256: 522862bf9939d11e4206346d6c187232d0729d5eac09ab5514ddfb4af431b881

Contents?: true

Size: 1.63 KB

Versions: 8

Compression:

Stored size: 1.63 KB

Contents

require "active_support/core_ext/module/attr_internal"

module Sequel
  module Rails
    module Railties
      module ControllerRuntime
        extend ActiveSupport::Concern

        protected

        attr_internal :db_runtime

        def process_action(action, *)
          # We also need to reset the runtime before each action
          # because of queries in middleware or in cases we are streaming
          # and it won't be cleaned up by the method below.
          ::Sequel::Rails::Railties::LogSubscriber.reset_runtime
          ::Sequel::Rails::Railties::LogSubscriber.reset_count
          super
        end

        def cleanup_view_runtime
          db_rt_before_render = ::Sequel::Rails::Railties::LogSubscriber.reset_runtime
          self.db_runtime = (db_runtime || 0) + db_rt_before_render
          runtime = super
          db_rt_after_render = ::Sequel::Rails::Railties::LogSubscriber.reset_runtime
          self.db_runtime += db_rt_after_render
          runtime - db_rt_after_render
        end

        def append_info_to_payload(payload)
          super
          payload[:db_runtime] = (db_runtime || 0) + ::Sequel::Rails::Railties::LogSubscriber.reset_runtime
          payload[:db_query_count] = ::Sequel::Rails::Railties::LogSubscriber.count
        end

        module ClassMethods
          def log_process_action(payload)
            messages = super
            messages << format("Database: %.1fms", payload[:db_runtime].to_f) if payload[:db_runtime]
            messages << format("Queries: %d", payload[:db_query_count].to_f) if payload[:db_query_count]
            messages
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sequelize-rails-1.0.0 lib/sequel/rails/railties/controller_runtime.rb
sequelize-rails-0.6.2 lib/sequel/rails/railties/controller_runtime.rb
sequelize-rails-0.6.1 lib/sequel/rails/railties/controller_runtime.rb
sequelize-rails-0.6.0 lib/sequel/rails/railties/controller_runtime.rb
sequelize-rails-0.5.0 lib/sequel/rails/railties/controller_runtime.rb
sequelize-rails-0.4.1 lib/sequel/rails/railties/controller_runtime.rb
sequelize-rails-0.4.0 lib/sequel/rails/railties/controller_runtime.rb
sequelize-rails-0.3.0 lib/sequel/rails/railties/controller_runtime.rb