mysql_dump_slow 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mysql_dump_slow/slow_log.rb +43 -0
- data/lib/mysql_dump_slow/summary.rb +1 -1
- data/lib/mysql_dump_slow/version.rb +1 -1
- data/lib/mysql_dump_slow.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbb45203ba1fe8b90b295bcc0e019efb4e674035
|
4
|
+
data.tar.gz: ae3d37189392c14db9bf977bc43f1057894320f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98536dd2677fdc321d486d794c6545b4b4363767ef0ccf761e4b74e4af817d405452edbf9a97b97e896d6a3613c2b84a842d7a476f6f369a25feffa23c79a4f5
|
7
|
+
data.tar.gz: f0bb83aa44dfeb8698be1f6d5fc92707a4f3d4f79f7aba098cfeb6b8bd8e99c45bf7bc8415ae90685fa907ba66fca29eed57e2f5eee6b4b2403c750cd54e0099
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module MysqlDumpSlow
|
2
|
+
class SlowLog
|
3
|
+
def initialize(logs)
|
4
|
+
@logs = logs
|
5
|
+
end
|
6
|
+
|
7
|
+
def find_each(options={})
|
8
|
+
return @logs.each{ |log| yield log } unless active_record_relation?
|
9
|
+
|
10
|
+
find_in_batches(options) do |records|
|
11
|
+
records.each { |record| yield record }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_in_batches(options={})
|
16
|
+
return @logs.each{ |log| yield log } unless active_record_relation?
|
17
|
+
|
18
|
+
batch_order = options[:batch_order] || :start_time
|
19
|
+
batch_size = options[:batch_size] || 1000
|
20
|
+
|
21
|
+
relation = @logs
|
22
|
+
relation = relation.reorder(batch_order).limit(batch_size)
|
23
|
+
records = relation.to_a
|
24
|
+
|
25
|
+
while records.any?
|
26
|
+
records_size = records.size
|
27
|
+
primary_key_offset = records.last.start_time
|
28
|
+
|
29
|
+
yield records
|
30
|
+
|
31
|
+
break if records_size < batch_size
|
32
|
+
|
33
|
+
records = relation.where("#{batch_order} > ?", primary_key_offset).to_a
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def active_record_relation?
|
40
|
+
defined?(ActiveRecord::Relation) && @logs.is_a?(ActiveRecord::Relation)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/mysql_dump_slow.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql_dump_slow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- monochromegane
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- bin/setup
|
85
85
|
- lib/mysql_dump_slow.rb
|
86
86
|
- lib/mysql_dump_slow/counter.rb
|
87
|
+
- lib/mysql_dump_slow/slow_log.rb
|
87
88
|
- lib/mysql_dump_slow/sql.rb
|
88
89
|
- lib/mysql_dump_slow/summary.rb
|
89
90
|
- lib/mysql_dump_slow/version.rb
|