sequel_pg 1.6.19 → 1.7.0

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: 2f3337f4ab6856e9ef371c69f82fa51c517afa49
4
- data.tar.gz: 9361f0cb030decc088eab639448e383c76030d26
3
+ metadata.gz: a6a40cb36583e8f82e16b3346ba16ae6bfd76f6f
4
+ data.tar.gz: fe8457e463a51d1bc522cb87a14236e4dfee23c4
5
5
  SHA512:
6
- metadata.gz: 43c2da7841e5d4b5a6e5bdd6f5d69fbb81e4cd8c6e7877f3bb3bbeafcf669d9a1fe22a2d57eef12bd1db17ab9a28d6a493a1a4261053c0250c23ec12cc6f679f
7
- data.tar.gz: 203ffd82e356f006305245f6dece26d5638c41ce1d7dbd0053885d7c53bcafc7775fcfeb1deabc8391bec9d0f3c0fb773aa82b914d23c928b8c8c5cd57713a1d
6
+ metadata.gz: a098d4cc78fa9c3f13c7cdd7fd88fe83f222d42c36acf258eb757eb99d5015dd5c7b4db6052f0429fe6a49a75de6b3982133ff4c80daeb8b68428bebee86a5e5
7
+ data.tar.gz: cd9d11acc5c408fd3f3868fdc2c3364d477292e22891d52005057db456cfbce09aea65f8d02935482d42fa2d2cfd8cbb09f05ba6401dbfa38239919a23c08c64
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === master
2
+
3
+ * Override Dataset#as_hash instead of #to_hash if #as_hash is defined (jeremyevans)
4
+
1
5
  === 1.6.19 (2017-06-13)
2
6
 
3
7
  * Use PG::Error instead of PGError if available, avoiding deprecation warning on pg 0.21.0+ (jeremyevans)
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  sequel_pg overwrites the inner loop of the Sequel postgres adapter
4
4
  row fetching code with a C version. The C version is significantly
5
- faster (2-6x) than the pure ruby version that Sequel uses by default.
5
+ faster than the pure ruby version that Sequel uses by default.
6
6
 
7
7
  == Real world difference
8
8
 
@@ -11,61 +11,39 @@ selecting, but it should be noticeable whenever many rows are selected.
11
11
  Here's an example that shows the difference it makes on a couple of
12
12
  models:
13
13
 
14
- $ irb -r model -r benchmark
15
- irb(main):001:0> Track.count
16
- => 140854
17
- irb(main):002:0> Album.count
18
- => 5579
19
- irb(main):003:0> puts Benchmark.measure{Track.each{}}
20
- 10.740000 0.190000 10.930000 ( 11.875343)
21
- => nil
22
- irb(main):004:0> puts Benchmark.measure{10.times{Album.each{}}}
23
- 7.920000 0.070000 7.990000 ( 8.482130)
24
- => nil
25
- irb(main):005:0> require '/data/code/sequel_pg/ext/sequel_pg/sequel_pg'
26
- => true
27
- irb(main):006:0> puts Benchmark.measure{Track.each{}}
28
- 2.360000 0.400000 2.760000 ( 3.723098)
29
- => nil
30
- irb(main):007:0> puts Benchmark.measure{10.times{Album.each{}}}
31
- 1.300000 0.190000 1.490000 ( 2.001393)
32
- => nil
33
-
34
- Here's an example that uses a modified version of swift's benchmarks
35
- (http://github.com/shanna/swift/tree/master/benchmarks/):
36
-
37
- benchmark sys user total real rss
38
- sequel #select 0.090000 2.020000 2.110000 2.246688 46.54m
39
- sequel_pg #select 0.000000 0.250000 0.250000 0.361999 7.33m
40
-
41
- sequel_pg also has code to speed up the map, to_hash, to_hash_groups,
42
- select_hash, select_hash_groups, select_map, and select_order_map
43
- Dataset methods, which is on by default. It also has code to speed
44
- up the loading of model objects, which is off by default as it isn't
45
- fully compatible. It doesn't handle overriding Model.call,
46
- Model#set_values, or Model#after_initialize, which may cause problems
47
- with the following plugins that ship with Sequel:
48
-
49
- * class_table_inheritance
50
- * force_encoding
51
- * serialization
52
- * single_table_inheritance
53
- * typecast_on_load
54
- * update_primary_key
55
-
56
- If you want to extract that last ounce of performance when loading
57
- model objects and you can live with the limitations, you can
58
- enable the model optimization via:
59
-
60
- # All datasets
61
- DB.optimize_model_load = true
62
-
63
- # Specific dataset
64
- Artist.dataset.optimize_model_load = true
14
+ Track.count # => 202261
15
+ Album.count # => 7264
16
+
17
+ Without sequel_pg:
18
+
19
+ puts Benchmark.measure{Track.each{}}
20
+ # 3.400000 0.290000 3.690000 ( 4.005150)
21
+ puts Benchmark.measure{10.times{Album.each{}}}
22
+ # 2.180000 0.120000 2.300000 ( 2.479352)
23
+
24
+ With sequel_pg:
25
+
26
+ puts Benchmark.measure{Track.each{}}
27
+ # 1.660000 0.260000 1.920000 ( 2.287216)
28
+ puts Benchmark.measure{10.times{Album.each{}}}
29
+ # 0.960000 0.110000 1.070000 ( 1.260913)
30
+
31
+ sequel_pg also speeds up the following Dataset methods:
32
+
33
+ * map
34
+ * as_hash/to_hash
35
+ * to_hash_groups,
36
+ * select_hash
37
+ * select_hash_groups
38
+ * select_map
39
+ * select_order_map
40
+
41
+ Additionally, in most cases sequel_pg also speeds up the loading of
42
+ model datasets by optimizing model instance creation.
65
43
 
66
44
  == Streaming
67
45
 
68
- If you are using PostgreSQL 9.2beta3 or higher on the client, then sequel_pg
46
+ If you are using PostgreSQL 9.2+ on the client, then sequel_pg
69
47
  should enable streaming support. This allows you to stream returned
70
48
  rows one at a time, instead of collecting the entire result set in
71
49
  memory (which is how PostgreSQL works by default). You can check
@@ -1,4 +1,4 @@
1
- #define SEQUEL_PG_VERSION_INTEGER 10619
1
+ #define SEQUEL_PG_VERSION_INTEGER 10700
2
2
 
3
3
  #include <string.h>
4
4
  #include <stdio.h>
@@ -1,14 +1,25 @@
1
1
  # Add speedup for model class creation from dataset
2
2
  class Sequel::Postgres::Database
3
- # Whether to optimize loads for all model datasets created from this dataset.
4
- # Has certain limitations, see the README for details.
5
- attr_accessor :optimize_model_load
3
+ def optimize_model_load=(v)
4
+ Sequel::Deprecation.deprecate("Database#optimize_model_load= is deprecated. Optimized model loading is now enabled by default, and can only be disabled on a per-Dataset basis.")
5
+ v
6
+ end
7
+ def optimize_model_load
8
+ Sequel::Deprecation.deprecate("Database#optimize_model_load is deprecated. Optimized model loading is now enabled by default, and can only be disabled on a per-Dataset basis.")
9
+ true
10
+ end
6
11
  end
7
12
 
8
- # Add faster versions of Dataset#map, #to_hash, #select_map, #select_order_map, and #select_hash
13
+ # Add faster versions of Dataset#map, #as_hash, #to_hash_groups, #select_map, #select_order_map, and #select_hash
9
14
  class Sequel::Postgres::Dataset
10
- # Set whether to enable optimized model loading for this dataset.
11
- attr_writer :optimize_model_load
15
+ def optimize_model_load=(v)
16
+ Sequel::Deprecation.deprecate("Dataset#optimize_model_load= mutation method is deprecated. Switch to using Dataset#with_optimize_model_load, which returns a modified dataset")
17
+ opts[:optimize_model_load] = v
18
+ end
19
+ def optimize_model_load
20
+ Sequel::Deprecation.deprecate("Dataset#optimize_model_load method is deprecated. Optimized model loading is enabled by default.")
21
+ opts.has_key?(:optimize_model_load) ? opts[:optimize_model_load] : true
22
+ end
12
23
 
13
24
  # In the case where an argument is given, use an optimized version.
14
25
  def map(sym=nil)
@@ -25,14 +36,13 @@ class Sequel::Postgres::Dataset
25
36
  end
26
37
  end
27
38
 
28
- # If this dataset has turned model loading on or off, use the default value from
29
- # the Database object.
30
- def optimize_model_load
31
- defined?(@optimize_model_load) ? @optimize_model_load : db.optimize_model_load
39
+ # Return a modified copy with the optimize_model_load setting changed.
40
+ def with_optimize_model_load(v)
41
+ clone(:optimize_model_load=>v)
32
42
  end
33
43
 
34
44
  # In the case where both arguments given, use an optimized version.
35
- def to_hash(key_column, value_column = nil, opts = Sequel::OPTS)
45
+ def as_hash(key_column, value_column = nil, opts = Sequel::OPTS)
36
46
  if value_column && !opts[:hash]
37
47
  clone(:_sequel_pg_type=>:hash, :_sequel_pg_value=>[key_column, value_column]).fetch_rows(sql){|s| return s}
38
48
  elsif opts.empty?
@@ -42,6 +52,12 @@ class Sequel::Postgres::Dataset
42
52
  end
43
53
  end
44
54
 
55
+ unless Sequel::Dataset.method_defined?(:as_hash)
56
+ # Handle previous versions of Sequel that use to_hash instead of as_hash
57
+ alias to_hash as_hash
58
+ remove_method :as_hash
59
+ end
60
+
45
61
  # In the case where both arguments given, use an optimized version.
46
62
  def to_hash_groups(key_column, value_column = nil, opts = Sequel::OPTS)
47
63
  if value_column && !opts[:hash]
@@ -53,13 +69,15 @@ class Sequel::Postgres::Dataset
53
69
  end
54
70
  end
55
71
 
56
- # If model loads are being optimized and this is a model load, use the optimized
57
- # version.
58
- def each
59
- if (rp = row_proc) && optimize_model_load?
60
- clone(:_sequel_pg_type=>:model, :_sequel_pg_value=>rp).fetch_rows(sql, &Proc.new)
61
- else
62
- super
72
+ if defined?(Sequel::Model::ClassMethods)
73
+ # If model loads are being optimized and this is a model load, use the optimized
74
+ # version.
75
+ def each
76
+ if optimize_model_load?
77
+ clone(:_sequel_pg_type=>:model, :_sequel_pg_value=>row_proc).fetch_rows(sql, &Proc.new)
78
+ else
79
+ super
80
+ end
63
81
  end
64
82
  end
65
83
 
@@ -81,10 +99,18 @@ class Sequel::Postgres::Dataset
81
99
 
82
100
  private
83
101
 
84
- # The model load can only be optimized if it's for a model and it's not a graphed dataset
85
- # or using a cursor.
86
- def optimize_model_load?
87
- (rp = row_proc).is_a?(Class) && (rp < Sequel::Model) && optimize_model_load && !opts[:use_cursor] && !opts[:graph]
102
+ if defined?(Sequel::Model::ClassMethods)
103
+ # The model load can only be optimized if it's for a model and it's not a graphed dataset
104
+ # or using a cursor.
105
+ def optimize_model_load?
106
+ (rp = row_proc) &&
107
+ rp.is_a?(Class) &&
108
+ rp < Sequel::Model &&
109
+ rp.method(:call).owner == Sequel::Model::ClassMethods &&
110
+ opts[:optimize_model_load] != false &&
111
+ !opts[:use_cursor] &&
112
+ !opts[:graph]
113
+ end
88
114
  end
89
115
  end
90
116
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.19
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-13 00:00:00.000000000 Z
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -41,7 +41,7 @@ dependencies:
41
41
  description: |
42
42
  sequel_pg overwrites the inner loop of the Sequel postgres
43
43
  adapter row fetching code with a C version. The C version
44
- is significantly faster (2-6x) than the pure ruby version
44
+ is significantly faster than the pure ruby version
45
45
  that Sequel uses by default.
46
46
 
47
47
  sequel_pg also offers optimized versions of some dataset