Sha256: 97a5c0a2fbd56a33f22128d575376c67377a182eb9f3230ac2aa00f6c9a08f08

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

module Blazer
  class RunStatement
    def perform(statement, options = {})
      query = options[:query]

      data_source = statement.data_source
      statement.bind

      # audit
      if Blazer.audit
        audit_statement = statement.bind_statement
        audit_statement += "\n\n#{statement.bind_values.to_json}" if statement.bind_values.any?
        audit = Blazer::Audit.new(statement: audit_statement)
        audit.query = query
        audit.data_source = data_source.id
        # only set user if present to avoid error with Rails 7.1 when no user model
        audit.user = options[:user] unless options[:user].nil?
        audit.save!
      end

      start_time = Blazer.monotonic_time
      result = data_source.run_statement(statement, options)
      duration = Blazer.monotonic_time - start_time

      if Blazer.audit
        audit.duration = duration if audit.respond_to?(:duration=)
        audit.error = result.error if audit.respond_to?(:error=)
        audit.timed_out = result.timed_out? if audit.respond_to?(:timed_out=)
        audit.cached = result.cached? if audit.respond_to?(:cached=)
        if !result.cached? && duration >= 10
          audit.cost = data_source.cost(statement) if audit.respond_to?(:cost=)
        end
        audit.save! if audit.changed?
      end

      if query && !result.timed_out? && !result.cached? && !query.variables.any?
        query.checks.each do |check|
          check.update_state(result)
        end
      end

      result
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
blazer-3.1.0 lib/blazer/run_statement.rb
blazer-3.0.4 lib/blazer/run_statement.rb
blazer_xlsx-3.0.8 lib/blazer/run_statement.rb
blazer_xlsx-3.0.7 lib/blazer/run_statement.rb
blazer_xlsx-3.0.6 lib/blazer/run_statement.rb
blazer_xlsx-3.0.5 lib/blazer/run_statement.rb
blazer-3.0.3 lib/blazer/run_statement.rb
blazer-3.0.2 lib/blazer/run_statement.rb
blazer-3.0.1 lib/blazer/run_statement.rb