blazer 2.6.2 → 2.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,9 @@ var runningQueries = []
3
3
  var maxQueries = 3
4
4
 
5
5
  function runQuery(data, success, error) {
6
+ if (!data.data_source) {
7
+ throw new Error("Data source is required to cancel queries")
8
+ }
6
9
  data.run_id = uuid()
7
10
  var query = {
8
11
  data: data,
@@ -50,7 +53,11 @@ function runQueryHelper(query) {
50
53
  queryComplete(query)
51
54
  }
52
55
  }).fail( function(jqXHR, textStatus, errorThrown) {
53
- if (!query.canceled) {
56
+ // check jqXHR.status instead of query.canceled
57
+ // so it works for page navigation with Firefox and Safari
58
+ if (jqXHR.status === 0) {
59
+ cancelServerQuery(query)
60
+ } else {
54
61
  var message = (typeof errorThrown === "string") ? errorThrown : errorThrown.message
55
62
  if (!message) {
56
63
  message = "An error occurred"
@@ -83,6 +90,8 @@ function cancelAllQueries() {
83
90
  }
84
91
  }
85
92
 
93
+ // needed for Chrome
94
+ // queries are canceled before unload with Firefox and Safari
86
95
  $(window).on("unload", cancelAllQueries)
87
96
 
88
97
  function cancelQuery(query) {
@@ -90,7 +99,9 @@ function cancelQuery(query) {
90
99
  if (query.xhr) {
91
100
  query.xhr.abort()
92
101
  }
102
+ }
93
103
 
104
+ function cancelServerQuery(query) {
94
105
  // tell server
95
106
  var path = Routes.cancel_queries_path()
96
107
  var data = {run_id: query.run_id, data_source: query.data_source}
@@ -92,6 +92,7 @@ module Blazer
92
92
  @cohort_analysis = @statement.cohort_analysis?
93
93
 
94
94
  # fallback for now for users with open tabs
95
+ # TODO remove fallback in future version
95
96
  @var_params = request.request_parameters["variables"] || request.request_parameters
96
97
  @success = process_vars(@statement, @var_params)
97
98
  @only_chart = params[:only_chart]
@@ -133,11 +134,11 @@ module Blazer
133
134
  options = {user: blazer_user, query: @query, refresh_cache: params[:check], run_id: @run_id, async: Blazer.async}
134
135
  if Blazer.async && request.format.symbol != :csv
135
136
  Blazer::RunStatementJob.perform_later(@data_source.id, @statement.statement, options.merge(values: @statement.values))
136
- wait_start = Time.now
137
+ wait_start = Blazer.monotonic_time
137
138
  loop do
138
139
  sleep(0.1)
139
140
  @result = @data_source.run_results(@run_id)
140
- break if @result || Time.now - wait_start > 3
141
+ break if @result || Blazer.monotonic_time - wait_start > 3
141
142
  end
142
143
  else
143
144
  @result = Blazer::RunStatement.new.perform(@statement, options)
@@ -39,7 +39,9 @@
39
39
  </div>
40
40
  </div>
41
41
  <script>
42
- <%= blazer_js_var "data", {statement: query.statement, query_id: query.id, variables: variable_params(query), only_chart: true, cohort_period: params[:cohort_period]} %>
42
+ <% data = {statement: query.statement, query_id: query.id, data_source: query.data_source, variables: variable_params(query), only_chart: true} %>
43
+ <% data.merge!(cohort_period: params[:cohort_period]) if params[:cohort_period] %>
44
+ <%= blazer_js_var "data", data %>
43
45
 
44
46
  runQuery(data, function (data) {
45
47
  $("#chart-<%= i %>").html(data)
@@ -1,10 +1,10 @@
1
1
  <% blazer_title @query.name %>
2
2
 
3
3
  <% if @success %>
4
- <% run_data = {statement: @query.statement, query_id: @query.id, variables: variable_params(@query)} %>
4
+ <% run_data = {statement: @query.statement, query_id: @query.id, data_source: @query.data_source, variables: variable_params(@query)} %>
5
5
  <% run_data.merge!(forecast: "t") if params[:forecast] %>
6
6
  <% run_data.merge!(cohort_period: params[:cohort_period]) if params[:cohort_period] %>
7
- <% run_data.transform_keys!(&:to_s) if Rails::VERSION::STRING.to_f == 5.0 %>
7
+ <% run_data.transform_keys!(&:to_s) if Rails::VERSION::MAJOR < 6 %>
8
8
  <% end %>
9
9
 
10
10
  <div class="topbar">
@@ -35,6 +35,9 @@ module Blazer
35
35
  error = e.message.sub(/.+ERROR: /, "")
36
36
  error = Blazer::TIMEOUT_MESSAGE if Blazer::TIMEOUT_ERRORS.any? { |e| error.include?(e) }
37
37
  error = Blazer::VARIABLE_MESSAGE if error.include?("syntax error at or near \"$") || error.include?("Incorrect syntax near '@") || error.include?("your MySQL server version for the right syntax to use near '?")
38
+ if error.include?("could not determine data type of parameter")
39
+ error += " - try adding casting to variables and make sure none are inside a string literal"
40
+ end
38
41
  reconnect if error.include?("PG::ConnectionBad")
39
42
  end
40
43
 
@@ -145,7 +145,7 @@ module Blazer
145
145
  end
146
146
 
147
147
  def statement_cache_key(statement)
148
- cache_key(["statement", id, Digest::MD5.hexdigest(statement.bind_statement.to_s.gsub("\r\n", "\n") + statement.bind_values.sort_by { |k, _| k }.to_json)])
148
+ cache_key(["statement", id, Digest::MD5.hexdigest(statement.bind_statement.to_s.gsub("\r\n", "\n") + statement.bind_values.to_json)])
149
149
  end
150
150
 
151
151
  def run_cache_key(run_id)
@@ -233,14 +233,14 @@ module Blazer
233
233
  end
234
234
 
235
235
  def run_statement_helper(statement, comment, run_id, options)
236
- start_time = Time.now
236
+ start_time = Blazer.monotonic_time
237
237
  columns, rows, error =
238
238
  if adapter_instance.parameter_binding
239
239
  adapter_instance.run_statement(statement.bind_statement, comment, statement.bind_values)
240
240
  else
241
241
  adapter_instance.run_statement(statement.bind_statement, comment)
242
242
  end
243
- duration = Time.now - start_time
243
+ duration = Blazer.monotonic_time - start_time
244
244
 
245
245
  cache_data = nil
246
246
  cache = !error && (cache_mode == "all" || (cache_mode == "slow" && duration >= cache_slow_threshold))
@@ -17,9 +17,9 @@ module Blazer
17
17
  audit.save!
18
18
  end
19
19
 
20
- start_time = Time.now
20
+ start_time = Blazer.monotonic_time
21
21
  result = data_source.run_statement(statement, options)
22
- duration = Time.now - start_time
22
+ duration = Blazer.monotonic_time - start_time
23
23
 
24
24
  if Blazer.audit
25
25
  audit.duration = duration if audit.respond_to?(:duration=)
@@ -1,3 +1,3 @@
1
1
  module Blazer
2
- VERSION = "2.6.2"
2
+ VERSION = "2.6.5"
3
3
  end
data/lib/blazer.rb CHANGED
@@ -257,6 +257,11 @@ module Blazer
257
257
  viewed_query_ids = Blazer::Audit.where("created_at > ?", 90.days.ago).group(:query_id).count.keys.compact
258
258
  Blazer::Query.active.where.not(id: viewed_query_ids).update_all(status: "archived")
259
259
  end
260
+
261
+ # private
262
+ def self.monotonic_time
263
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
264
+ end
260
265
  end
261
266
 
262
267
  Blazer.register_adapter "athena", Blazer::Adapters::AthenaAdapter
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blazer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.2
4
+ version: 2.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-06 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties