quick_count 0.1.0 → 0.1.1
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 +5 -5
- data/CHANGELOG.md +3 -0
- data/README.md +6 -3
- data/lib/count_estimate/active_record/relation.rb +15 -0
- data/lib/quick_count/active_record/base.rb +20 -0
- data/lib/quick_count/version.rb +1 -1
- data/lib/quick_count.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b96ac3ad5c0ecf19aaa83bdda2805c30221b26ae36d19a614aaa637cf2a52dbc
|
4
|
+
data.tar.gz: f42909f6a0a932e98329d4e4676cdc085db7aceac847fcd035746cbfd652439b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30d43a8f2dca676c28c68b8f94fb699f09c9af067f27f8cfe7a9332c6ed322e10ac745130e9e0f21b74157fb9dcdee4b696115b1483f1054eb4e60d992bcd42d
|
7
|
+
data.tar.gz: 0aae2ca316cb80fe2bab834bc2ed95769897db442ab186931d17fa1de2a01d923834eca1beb37518d913409a679177adf949f6a95f2b6cae4d3465046f981cc9
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
[](https://rubygems.org/gems/quick_count)
|
2
2
|
[](https://travis-ci.org/TwilightCoders/quick_count)
|
3
3
|
[](https://codeclimate.com/github/TwilightCoders/quick_count/maintainability)
|
4
|
-
[](https://depfu.com/github/TwilightCoders/quick_count)
|
4
|
+
[](https://codeclimate.com/github/TwilightCoders/quick_count/test_coverage)
|
6
5
|
|
7
6
|
# QuickCount
|
8
7
|
|
@@ -44,6 +43,10 @@ Or install it yourself as:
|
|
44
43
|
|
45
44
|
$ gem install quick_count
|
46
45
|
|
46
|
+
To finish the install, in rails console:
|
47
|
+
|
48
|
+
$ QuickCount.install # Install with default (500000) threshold
|
49
|
+
|
47
50
|
## Usage
|
48
51
|
|
49
52
|
```ruby
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module CountEstimate
|
4
|
+
module ActiveRecord
|
5
|
+
module Relation
|
6
|
+
|
7
|
+
def count_estimate
|
8
|
+
my_statement = ::ActiveRecord::Base.connection.quote(to_sql)
|
9
|
+
result = ::ActiveRecord::Base.connection.execute("SELECT count_estimate(#{my_statement})")
|
10
|
+
result[0]["count_estimate"].to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module QuickCount
|
4
|
+
module ActiveRecord
|
5
|
+
module Base
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def quick_count(threshold: nil)
|
11
|
+
threshold = threshold ? ", #{threshold}" : nil
|
12
|
+
result = ::ActiveRecord::Base.connection.execute("SELECT quick_count('#{table_name}'#{threshold})")
|
13
|
+
result[0]["quick_count"].to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/quick_count/version.rb
CHANGED
data/lib/quick_count.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quick_count
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Stevens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -132,8 +132,10 @@ files:
|
|
132
132
|
- LICENSE
|
133
133
|
- README.md
|
134
134
|
- lib/count_estimate/active_record.rb
|
135
|
+
- lib/count_estimate/active_record/relation.rb
|
135
136
|
- lib/quick_count.rb
|
136
137
|
- lib/quick_count/active_record.rb
|
138
|
+
- lib/quick_count/active_record/base.rb
|
137
139
|
- lib/quick_count/railtie.rb
|
138
140
|
- lib/quick_count/version.rb
|
139
141
|
homepage: https://github.com/TwilightCoders/quick_count
|
@@ -158,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
160
|
version: '0'
|
159
161
|
requirements: []
|
160
162
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.7.7
|
162
164
|
signing_key:
|
163
165
|
specification_version: 4
|
164
166
|
summary: Quickly get an accurate count estimation for large tables.
|