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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e44c57040c2a9cc336b30e839fd0c5c69fe37d4
4
- data.tar.gz: 200d9f11707ca8670faa3a92daddae7cd88ccca8
3
+ metadata.gz: cbb45203ba1fe8b90b295bcc0e019efb4e674035
4
+ data.tar.gz: ae3d37189392c14db9bf977bc43f1057894320f8
5
5
  SHA512:
6
- metadata.gz: e44086d502cd8d0e12ba9bf264bdf22d31b9a937eb99d48e0e04515587abceaf84c0c983a770b1e73bb1adc4cbaf5188af2c41c9dacefbe5576475aceea1fffd
7
- data.tar.gz: f97b94b75c2c415e90ccdcdf45c775ad446c6afbb00ca46bc193c50ffe292bc5ff1ee875381753ff1ce36c4e3826648537db5a527cd419bc85acb5cc8201a691
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
@@ -3,7 +3,7 @@ module MysqlDumpSlow
3
3
  include Enumerable
4
4
 
5
5
  def initialize(logs)
6
- @logs = logs
6
+ @logs = SlowLog.new(logs)
7
7
  summarize
8
8
  end
9
9
 
@@ -1,3 +1,3 @@
1
1
  module MysqlDumpSlow
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "mysql_dump_slow/version"
2
2
  require "mysql_dump_slow/counter"
3
3
  require "mysql_dump_slow/sql"
4
+ require "mysql_dump_slow/slow_log"
4
5
  require "mysql_dump_slow/summary"
5
6
 
6
7
  module MysqlDumpSlow
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.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