periscope_rails 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- periscope_rails (0.0.5)
4
+ periscope_rails (0.0.6)
5
5
  activesupport (~> 3.0)
6
6
  rails (~> 3.0)
7
7
 
@@ -36,25 +36,26 @@ class PeriscopeController < ActionController::Base
36
36
  elsif (command_words & bad_words).size > 0
37
37
  error_message = "Potentially harmful keyword found, blocking script."
38
38
  else
39
- begin
39
+ begin #for whole query
40
40
  active_record = PeriscopeRails::Config.get_active_record()
41
- active_record.transaction do
42
- if PeriscopeRails::Config.block_expensive_queries?
43
- cost_row = ""
44
- begin
45
- cost_row = active_record.connection.select_all("explain #{command}")[0]["QUERY PLAN"]
46
- rescue
47
- puts "Warning: Periscope was unable to cost this query (1): #{command}"
48
- end
49
- cost_row =~ /rows=(\d+) width=(\d+)\)$/
50
- row_count, width = $1.to_i, $2.to_i
51
- if row_count > 0 and width > 0
52
- raise "Command blocked, it may be too slow. Estimated at #{row_count} rows, commands must return fewer than #{PeriscopeRails::Config.max_rows} rows." if row_count > PeriscopeRails::Config.max_rows
53
- raise "Command blocked, it may be too slow. Estimated at #{row_count * width} bytes, commands use less than #{PeriscopeRails::Config.max_size} bytes." if row_count * width > PeriscopeRails::Config.max_size
54
- else
55
- puts "Warning: Periscope was unable to cost this query (2): #{command}"
41
+ begin #just for costing
42
+ active_record.transaction do #costing
43
+ if PeriscopeRails::Config.block_expensive_queries?
44
+ active_record.connection.select_all("explain #{command}")[0]["QUERY PLAN"] =~ /rows=(\d+) width=(\d+)\)$/
45
+ row_count, width = $1.to_i, $2.to_i
46
+ if row_count > 0 and width > 0
47
+ raise "Command blocked, it may be too slow. Estimated at #{row_count} rows, commands must return fewer than #{PeriscopeRails::Config.max_rows} rows." if row_count > PeriscopeRails::Config.max_rows
48
+ raise "Command blocked, it may be too slow. Estimated at #{row_count * width} bytes, commands use less than #{PeriscopeRails::Config.max_size} bytes." if row_count * width > PeriscopeRails::Config.max_size
49
+ else
50
+ puts "Warning: Periscope was unable to cost this query (2): #{command}"
51
+ end
56
52
  end
53
+ raise "OK" #abort all transactions for extra protection
57
54
  end
55
+ rescue Exception => e
56
+ puts "Warning: Periscope was unable to cost this query (1): #{command}" unless e.message == "OK"
57
+ end
58
+ active_record.transaction do #execution
58
59
  rows = active_record.connection.select_all(command)
59
60
  rows.each do |row|
60
61
  row.each_key do |column|
@@ -1,3 +1,3 @@
1
1
  module PeriscopeRails
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.summary = "Rails API for Periscope Database Viewer"
12
12
  s.description = "Periscope allows you to query your production database. The gem provides the API for Periscope to communicate with your Rails app."
13
13
  s.files = Dir["{app,lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"]
14
- s.version = "0.0.5"
14
+ s.version = "0.0.6"
15
15
 
16
16
  s.add_dependency "activesupport" , "~> 3.0"
17
17
  s.add_dependency "rails" , "~> 3.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: periscope_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-10 00:00:00.000000000Z
13
+ date: 2012-05-15 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &26545716 !ruby/object:Gem::Requirement
17
+ requirement: &27484104 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *26545716
25
+ version_requirements: *27484104
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rails
28
- requirement: &26545428 !ruby/object:Gem::Requirement
28
+ requirement: &27483816 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *26545428
36
+ version_requirements: *27483816
37
37
  description: Periscope allows you to query your production database. The gem provides
38
38
  the API for Periscope to communicate with your Rails app.
39
39
  email: