query_diet 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/query_diet/logger.rb +12 -6
- data/lib/query_diet/version.rb +1 -1
- data/spec/shared/query_diet/logger_spec.rb +24 -0
- metadata +4 -5
- data/VERSION +0 -1
data/lib/query_diet/logger.rb
CHANGED
@@ -3,19 +3,21 @@ module QueryDiet
|
|
3
3
|
DEFAULT_OPTIONS = { :bad_count => 8, :bad_time => 5000 }
|
4
4
|
|
5
5
|
class << self
|
6
|
-
attr_accessor :queries
|
6
|
+
attr_accessor :queries, :paused
|
7
7
|
|
8
8
|
def reset
|
9
9
|
self.queries = []
|
10
10
|
end
|
11
11
|
|
12
12
|
def log(query)
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
unless paused?
|
14
|
+
result = nil
|
15
|
+
time = Benchmark.realtime do
|
16
|
+
result = yield
|
17
|
+
end
|
18
|
+
queries << [query, time] if log_query?(query)
|
19
|
+
result
|
16
20
|
end
|
17
|
-
queries << [query, time] if log_query?(query)
|
18
|
-
result
|
19
21
|
end
|
20
22
|
|
21
23
|
def time
|
@@ -31,6 +33,10 @@ module QueryDiet
|
|
31
33
|
count >= options[:bad_count] or time >= options[:bad_time]
|
32
34
|
end
|
33
35
|
|
36
|
+
def paused?
|
37
|
+
paused
|
38
|
+
end
|
39
|
+
|
34
40
|
private
|
35
41
|
|
36
42
|
def log_query?(query)
|
data/lib/query_diet/version.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe QueryDiet::Logger do
|
4
|
+
|
4
5
|
before do
|
5
6
|
QueryDiet::Logger.reset
|
6
7
|
end
|
@@ -47,4 +48,27 @@ describe QueryDiet::Logger do
|
|
47
48
|
query[1].should == 5.1234
|
48
49
|
end
|
49
50
|
end
|
51
|
+
|
52
|
+
describe "#paused" do
|
53
|
+
|
54
|
+
it "should be false by default" do
|
55
|
+
QueryDiet::Logger.paused.should be_false
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should pause the query count" do
|
59
|
+
Movie.create
|
60
|
+
Movie.create
|
61
|
+
QueryDiet::Logger.count.should == 2
|
62
|
+
|
63
|
+
QueryDiet::Logger.paused = true
|
64
|
+
Movie.create
|
65
|
+
QueryDiet::Logger.count.should == 2
|
66
|
+
|
67
|
+
QueryDiet::Logger.paused = false
|
68
|
+
Movie.create
|
69
|
+
QueryDiet::Logger.count.should == 3
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
50
74
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_diet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2013-05-17 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
@@ -33,7 +33,6 @@ files:
|
|
33
33
|
- MIT-LICENSE
|
34
34
|
- README.rdoc
|
35
35
|
- Rakefile
|
36
|
-
- VERSION
|
37
36
|
- lib/query_diet.rb
|
38
37
|
- lib/query_diet/active_record_ext.rb
|
39
38
|
- lib/query_diet/logger.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.3.1
|