fast_inserter 0.1.3 → 0.1.4

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: 73fb3eacb5a0e1b3bbca479f5d900092530dd5a4
4
- data.tar.gz: d10d296537aa9f02f6db25876a26546ce22de053
3
+ metadata.gz: c9a5654ca484c5f0b47bfa91c6f5e1bb52549933
4
+ data.tar.gz: 9d239e735b0333d3662dc663e5fb5dfb83a6bee3
5
5
  SHA512:
6
- metadata.gz: aa0bd1c5463e94174a4cdf3b8f3a2750ff582deee8dd2fa9c73568393aaa498363bc493a631421092cb92971fe38a97148e448fda1289e0b6bc257e5d458b0d4
7
- data.tar.gz: b3d6b231cf413cf101e04eda02da00e2547b9e393584ccc9310b7a427c9ae4cb3a2c3371311b63756656eb6170c842075c11854dc660ce237433eefde65c4914
6
+ metadata.gz: 9c89ce208dc7b8bcfb95b4bdb8e632b8712cc47bb7348f0f88d67ec83ccf986b69d565b8f66fc880f629ae12f909b13d89beeae960c431e3ab77f1a4f67486c5
7
+ data.tar.gz: a65992d6071b696bbc25b523002fcb5a32d84d4b0733f07f4a91c52cc4eef96f49947225bdf0431c1443d2a738eb36375dec7b29d2981cb9ee1b95eeea550e40
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.4 (September 19, 2016) ##
2
+
3
+ * Improve performance when checking for existing records.
4
+
5
+ *Scott Ringwelski*
6
+
1
7
  ## 0.1.3 (August 26, 2016) ##
2
8
 
3
9
  * Lower the batch size
@@ -94,20 +94,24 @@ module FastInserter
94
94
 
95
95
  # Queries for the existing values for a given group of values
96
96
  def existing_values(group_of_values)
97
- values_to_check = ActiveRecord::Base.send(:sanitize_sql_array, ["?", group_of_values])
98
- sql = "SELECT #{@variable_column} FROM #{@table_name} WHERE #{existing_values_static_columns} AND #{@variable_column} IN (#{values_to_check})"
97
+ sql = "SELECT #{@variable_column} FROM #{@table_name} WHERE #{existing_values_static_columns}"
99
98
 
100
99
  # NOTE: There are more elegant ways to get this field out of the resultset, but each database adaptor returns a different type
101
100
  # of result from 'execute(sql)'. Potential classes for 'result' is Array (sqlite), Mysql2::Result (mysql2), PG::Result (pg). Each
102
101
  # result can be enumerated into a list of arrays (mysql) or list of hashes (sqlite, pg)
103
102
  results = ActiveRecord::Base.connection.execute(sql)
104
- results.to_a.map do |result|
103
+ existing_values = results.to_a.map do |result|
105
104
  if result.is_a?(Hash)
106
105
  result[@variable_column].to_s
107
106
  elsif result.is_a?(Array)
108
107
  result[0].to_s
109
108
  end
110
109
  end
110
+
111
+ # Rather than a giant IN query in the sql statement (which can be bad for database performance),
112
+ # do the filtering of relevant values here in a ruby select.
113
+ group_of_values_strings = group_of_values.map(&:to_s)
114
+ existing_values & group_of_values_strings
111
115
  end
112
116
 
113
117
  def existing_values_static_columns
@@ -1,3 +1,3 @@
1
1
  module FastInserter
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_inserter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Ringwelski
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2016-08-27 00:00:00.000000000 Z
14
+ date: 2016-09-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activerecord