sequel_pg 1.6.19 → 1.7.0
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 +4 -4
- data/CHANGELOG +4 -0
- data/README.rdoc +31 -53
- data/ext/sequel_pg/sequel_pg.c +1 -1
- data/lib/sequel_pg/sequel_pg.rb +48 -22
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6a40cb36583e8f82e16b3346ba16ae6bfd76f6f
|
4
|
+
data.tar.gz: fe8457e463a51d1bc522cb87a14236e4dfee23c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a098d4cc78fa9c3f13c7cdd7fd88fe83f222d42c36acf258eb757eb99d5015dd5c7b4db6052f0429fe6a49a75de6b3982133ff4c80daeb8b68428bebee86a5e5
|
7
|
+
data.tar.gz: cd9d11acc5c408fd3f3868fdc2c3364d477292e22891d52005057db456cfbce09aea65f8d02935482d42fa2d2cfd8cbb09f05ba6401dbfa38239919a23c08c64
|
data/CHANGELOG
CHANGED
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
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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.
|
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
|
data/ext/sequel_pg/sequel_pg.c
CHANGED
data/lib/sequel_pg/sequel_pg.rb
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
# Add speedup for model class creation from dataset
|
2
2
|
class Sequel::Postgres::Database
|
3
|
-
|
4
|
-
|
5
|
-
|
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, #
|
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
|
-
|
11
|
-
|
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
|
-
#
|
29
|
-
|
30
|
-
|
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
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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.
|
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-
|
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
|
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
|