data_pitcher 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9160b5110005e8d31749729dfdfedd2172fc0327
4
- data.tar.gz: 12a7743e035d76d11fce3946e41b055e2f464525
3
+ metadata.gz: 8025404be932416fdf0b9bbd08d08f22cdf31469
4
+ data.tar.gz: 29b8bc521481415d5412bd4114f316ad3fb7d718
5
5
  SHA512:
6
- metadata.gz: 3a29f48edb6a2906826b044a8d416fa8153661efa00a99b7bebefd86eb81078dfc90993d9569182d370549fc81ae0b1339e4b8cae9ef361cc64b037dad2e4e35
7
- data.tar.gz: 2f425a302fcfc7132fce72f89a80d5000f65409649838fdf523c9e916a97b2be8c2c3a112e4769fde5c0f48390bc1e8dc8fff4e3d53a233501c28888c3a9d237
6
+ metadata.gz: 8c75433570a7a09727e2e51c9f8ee0ba535166dc108b2ba4a8a23aa098144fea6c4eceed56b74801cb8f80720a23c42bcee1e47b5f95a9ea9de6dbee2653a2ea
7
+ data.tar.gz: 9ee9e905e4915689e1181d6f6867758edae4693ad9160246de1f804898b2f9160727acdddc0f308800aed12f97c70c74085b24b5df462de2fcfb7c9d037d821b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- data_pitcher (0.1.1)
4
+ data_pitcher (0.1.2)
5
5
  activerecord (>= 3.2)
6
6
  google_drive
7
7
 
@@ -14,8 +14,12 @@ module DataPitcher
14
14
  def execute(dry_run: true)
15
15
  commands.each.with_index(1) do |command, index|
16
16
  begin
17
- if DataPitcher::Command.new(command['spreadsheet_key'], command['sql_path'], dry_run: dry_run, index: index).execute
18
- puts "##{index} command: sending completed."
17
+ result = false
18
+ elapsed_time = Benchmark.realtime do
19
+ result = DataPitcher::Command.new(command['spreadsheet_key'], command['sql_path'], dry_run: dry_run, index: index).execute
20
+ end
21
+ if result
22
+ puts "##{index} command: sending completed. #{elapsed_time}s"
19
23
  end
20
24
  rescue => e
21
25
  puts "[ERROR] ##{index} command skipped: #{e.class} #{e.message}"
@@ -26,6 +26,7 @@ module DataPitcher
26
26
  return false
27
27
  end
28
28
  spreadsheet.replace_worksheet_with_query(sql_query)
29
+ true
29
30
  end
30
31
 
31
32
  def spreadsheet
@@ -2,6 +2,8 @@ require 'google_drive'
2
2
 
3
3
  module DataPitcher
4
4
  class Spreadsheet
5
+ BATCH_SIZE = 1000
6
+
5
7
  def initialize(spreadsheet_key)
6
8
  @spreadsheet_key = spreadsheet_key
7
9
  end
@@ -17,11 +19,7 @@ module DataPitcher
17
19
 
18
20
  def clear_sheet
19
21
  worksheet.reload
20
- (1..worksheet.num_rows).each do |row|
21
- (1..worksheet.num_cols).each do |col|
22
- worksheet[row, col] = ''
23
- end
24
- end
22
+ worksheet.delete_rows(1, worksheet.num_rows)
25
23
  worksheet.save
26
24
  end
27
25
 
@@ -29,16 +27,12 @@ module DataPitcher
29
27
  result = DataPitcher::Executor.new(sql_query).execute
30
28
  worksheet.reload
31
29
  # fill header
32
- result.header.each.with_index(1) do |val, col_index|
33
- worksheet[1, col_index] = val
34
- end
30
+ worksheet.insert_rows(1, [result.header])
35
31
  # fill rows
36
- result.rows.each.with_index(2) do |row, row_index|
37
- row.each.with_index(1) do |val, col_index|
38
- worksheet[row_index, col_index] = val
39
- end
32
+ result.rows.each_slice(BATCH_SIZE).with_index do |array, batch_index|
33
+ worksheet.insert_rows(2 + batch_index * BATCH_SIZE, array)
34
+ worksheet.save
40
35
  end
41
- worksheet.save
42
36
  end
43
37
 
44
38
  def replace_worksheet_with_query(sql_query)
@@ -1,3 +1,3 @@
1
1
  module DataPitcher
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_pitcher
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
  - Masahiro Nishimi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-26 00:00:00.000000000 Z
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord