simple-sql 0.4.35 → 0.4.36

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
  SHA256:
3
- metadata.gz: e64bdc8330b5c64d7e7e17d44a008b0b54e60c9061f524bd1f66ededde5505a4
4
- data.tar.gz: 0f07ebf046e8c136126bf5328d46de1dde14e4257389f490acdf4c1746f8cc0b
3
+ metadata.gz: a8dc1ec7e4bb737434a4bcd95b612b9e100386bbc2896d67e09b68b6c7946172
4
+ data.tar.gz: a3cfb7860e3c085514b4e294b7b99773cd2365292ca68e96bc81ede0c10fc8c7
5
5
  SHA512:
6
- metadata.gz: 95c29b91172bfe37d18607199b7ffd103b54b1cfbafe0ba8a5f4bbb3c70b21ec0357a49783dfeab3de9e04eea536a05513e59a5e68d307bcca186fe8671f5ce0
7
- data.tar.gz: 9a673939c8ea707d61a8ef105e684996237198f771e8869bfa9b824e6be591e34ef461243f486af278387f7c25ff7ff74ab43c6bbcf69bba03b26d3b51ad12e1
6
+ metadata.gz: e3de0a9214dce2e7fc91de037fb58dc4beef47ee066acfdf366e2b6100f1a4592436078d13c34d34cbc102be25c5281b0177aace3b5c36be30dc0ed735e3438f
7
+ data.tar.gz: fdb5081fae742c348157af72bcb119cc61ad88831f313fa640a64020ff6254c65ba1e662325bd684a92dda27c2d0f3bb40a7c0ef4dd8af82b3b7cdee0fdc59b9
@@ -34,15 +34,17 @@ class ::Simple::SQL::Result < Array
34
34
  #
35
35
  # This is filled in when resolving a paginated scope.
36
36
  def total_count_estimate
37
- @total_count_estimate ||= catch(:total_count_estimate) do
38
- scope = @pagination_scope
39
- scope_sql = scope.order_by(nil).to_sql(pagination: false)
40
- ::Simple::SQL.each("EXPLAIN #{scope_sql}", *scope.args) do |line|
41
- next unless line =~ /\brows=(\d+)/
42
-
43
- throw :total_count_estimate, Integer($1)
37
+ return @total_count_estimate if instance_variable_defined?(:@total_count_estimate)
38
+
39
+ @total_count_estimate = if @pagination_scope
40
+ catch(:total_count_estimate) do
41
+ sql = @pagination_scope.order_by(nil).to_sql(pagination: false)
42
+ ::Simple::SQL.each("EXPLAIN #{sql}", *@pagination_scope.args) do |line|
43
+ next unless line =~ /\brows=(\d+)/
44
+ throw :total_count_estimate, Integer($1)
45
+ end
46
+ -1
44
47
  end
45
- -1
46
48
  end
47
49
  end
48
50
 
@@ -50,17 +52,20 @@ class ::Simple::SQL::Result < Array
50
52
  #
51
53
  # This is filled in when resolving a paginated scope.
52
54
  def total_pages_estimate
53
- @total_pages_estimate ||= (total_count_estimate * 1.0 / @pagination_scope.per).ceil
55
+ return @total_pages_estimate if instance_variable_defined?(:@total_pages_estimate)
56
+
57
+ @total_pages_estimate = (total_count_estimate * 1.0 / @pagination_scope.per).ceil if @pagination_scope
54
58
  end
55
59
 
56
60
  # returns the total_count of search hits
57
61
  #
58
62
  # This is filled in when resolving a paginated scope.
59
63
  def total_count
60
- @total_count ||= begin
61
- scope = @pagination_scope
62
- scope_sql = scope.order_by(nil).to_sql(pagination: false)
63
- ::Simple::SQL.ask("SELECT COUNT(*) FROM (#{scope_sql}) simple_sql_count", *scope.args)
64
+ return @total_count if instance_variable_defined?(:@total_count)
65
+
66
+ @total_count = if @pagination_scope
67
+ sql = @pagination_scope.order_by(nil).to_sql(pagination: false)
68
+ ::Simple::SQL.ask("SELECT COUNT(*) FROM (#{sql}) _total_count", *@pagination_scope.args)
64
69
  end
65
70
  end
66
71
 
@@ -69,7 +74,9 @@ class ::Simple::SQL::Result < Array
69
74
  # This is filled in when resolving a paginated scope. It takes
70
75
  # into account the scope's "per" option.
71
76
  def total_pages
72
- @total_pages ||= (total_count * 1.0 / @pagination_scope.per).ceil
77
+ return @total_pages if instance_variable_defined?(:@total_pages)
78
+
79
+ @total_pages = (total_count * 1.0 / @pagination_scope.per).ceil if @pagination_scope
73
80
  end
74
81
 
75
82
  # returns the current page number in a paginated search
@@ -1,5 +1,5 @@
1
1
  module Simple
2
2
  module SQL
3
- VERSION = "0.4.35"
3
+ VERSION = "0.4.36"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.35
4
+ version: 0.4.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - radiospiel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-03-21 00:00:00.000000000 Z
12
+ date: 2019-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pg_array_parser
@@ -267,8 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
267
  - !ruby/object:Gem::Version
268
268
  version: '0'
269
269
  requirements: []
270
- rubyforge_project:
271
- rubygems_version: 2.7.6
270
+ rubygems_version: 3.0.2
272
271
  signing_key:
273
272
  specification_version: 4
274
273
  summary: SQL with a simple interface