quick_count 0.0.6 → 0.1.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
- SHA256:
3
- metadata.gz: 13b6d1774446b930452cb50814ff1081c01353f0136f1b60706f57481bfe5e7f
4
- data.tar.gz: 2cda68595ddd0c78af1b7baacf67639011803d073d72e98a38a030d15df17fef
2
+ SHA1:
3
+ metadata.gz: f66820d33c95c3c038829d7fc456850301d5514f
4
+ data.tar.gz: 4117c911a066b29f324bc7dc8ad4e093a70ada3c
5
5
  SHA512:
6
- metadata.gz: 0b2fd37276fbcff9a6dcc0892908389f0f6dbd228133f52e20bd380eb8b66dc446ea597e98d68f9955b3fbb14b5040f38d84d396efc909bc8b332e28154acd38
7
- data.tar.gz: 49a10a20fbd02043c36978c97dbcd9c744bea945cc8166fd3e0ecb5083364c4f2b2f5f3d2dd93a11068e854197b1f84aecd3c06aeaeda2589fb4a382edffdb2c
6
+ metadata.gz: 8f1b35c2ff31bc1c80ae3a31472b08b12047a9951253a3030dbeac450d3e633500e3a56bd09d9f63195ffcdb474c451b5209df80975d03a70feee6d3ae24c4ef
7
+ data.tar.gz: 23b26e62eaf837bc6f999531f0d123c1c1501a7cea95993363ff1939240ecc9186572943bcd2a633065d7956cc584919c09c5142b1765d1b7588b790ac1e594a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # QuickCount
2
2
 
3
+ ## 0.1.0 _(June 22nd 2018)_
4
+ - Unlock `pg` gem (allow for > 0.2.x)
5
+ - Cleaned up gemspec and what it bundles in the gem
6
+ - Cleaned up some files/module names
7
+
3
8
  ## 0.0.6 _(March 17th 2018)_
4
9
  - Improved accuracy of `quick_count` by an average of 2.16%
5
10
  - Configurable threshold
@@ -1,4 +1,4 @@
1
- Copyright 2017 Dale Stevens
1
+ Copyright 2018 Dale Stevens
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Build Status ](https://travis-ci.org/TwilightCoders/quick_count.svg)](https://travis-ci.org/TwilightCoders/quick_count)
3
3
  [![Code Climate ](https://api.codeclimate.com/v1/badges/43ba3e038a91b44fba2c/maintainability)](https://codeclimate.com/github/TwilightCoders/quick_count/maintainability)
4
4
  [![Test Coverage](https://codeclimate.com/github/TwilightCoders/quick_count/badges/coverage.svg)](https://codeclimate.com/github/TwilightCoders/quick_count/coverage)
5
- [![Dependency Status](https://gemnasium.com/badges/github.com/TwilightCoders/quick_count.svg)](https://gemnasium.com/github.com/TwilightCoders/quick_count)
5
+ [![Dependencies ](https://badges.depfu.com/badges/564300bfe49871ba217a3f78de3ecc0c/overview.svg)](https://depfu.com/github/TwilightCoders/quick_count)
6
6
 
7
7
  # QuickCount
8
8
 
@@ -0,0 +1,13 @@
1
+ require 'active_support/concern'
2
+
3
+ module CountEstimate
4
+ module ActiveRecord
5
+
6
+ def count_estimate
7
+ my_statement = ::ActiveRecord::Base.connection.quote(to_sql)
8
+ result = ::ActiveRecord::Base.connection.execute("SELECT count_estimate(#{my_statement})")
9
+ result[0]["count_estimate"].to_i
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'active_support/concern'
2
+
3
+ module QuickCount
4
+ module ActiveRecord
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+
9
+ def quick_count(threshold: nil)
10
+ threshold = threshold ? ", #{threshold}" : nil
11
+ result = ::ActiveRecord::Base.connection.execute("SELECT quick_count('#{table_name}'#{threshold})")
12
+ result[0]["quick_count"].to_i
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -1,6 +1,6 @@
1
1
  require 'rails/railtie'
2
- require 'quick_count/active_record/base'
3
- require 'count_estimate/active_record/relation'
2
+ require 'quick_count/active_record'
3
+ require 'count_estimate/active_record'
4
4
 
5
5
  module QuickCount
6
6
  class Railtie < Rails::Railtie
@@ -1,3 +1,3 @@
1
1
  module QuickCount
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/quick_count.rb CHANGED
@@ -9,8 +9,8 @@ module QuickCount
9
9
  end
10
10
 
11
11
  def self.load
12
- ::ActiveRecord::Base.send :include, QuickCount::ActiveRecord::Base
13
- ::ActiveRecord::Relation.send :include, CountEstimate::ActiveRecord::Relation
12
+ ::ActiveRecord::Base.send :include, QuickCount::ActiveRecord
13
+ ::ActiveRecord::Relation.send :include, CountEstimate::ActiveRecord
14
14
  end
15
15
 
16
16
  def self.install(threshold: 500000, schema: 'public')
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick_count
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
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-03-18 00:00:00.000000000 Z
11
+ date: 2018-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.20'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.20'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -128,33 +128,14 @@ executables: []
128
128
  extensions: []
129
129
  extra_rdoc_files: []
130
130
  files:
131
- - ".gitignore"
132
- - ".travis.yml"
133
131
  - CHANGELOG.md
134
- - Gemfile
135
- - MIT-LICENSE
132
+ - LICENSE
136
133
  - README.md
137
- - Rakefile
138
- - gemfiles/activerecord-4.0.Gemfile
139
- - gemfiles/activerecord-4.1.Gemfile
140
- - gemfiles/activerecord-4.2.Gemfile
141
- - gemfiles/activerecord-5.0.Gemfile
142
- - gemfiles/activerecord-5.1.Gemfile
143
- - lib/count_estimate/active_record/relation.rb
134
+ - lib/count_estimate/active_record.rb
144
135
  - lib/quick_count.rb
145
- - lib/quick_count/active_record/base.rb
136
+ - lib/quick_count/active_record.rb
146
137
  - lib/quick_count/railtie.rb
147
138
  - lib/quick_count/version.rb
148
- - quick_count.gemspec
149
- - spec/quick_count_spec.rb
150
- - spec/spec_helper.rb
151
- - spec/support/rails/app/models/post.rb
152
- - spec/support/rails/app/models/user.rb
153
- - spec/support/rails/config/database.yml
154
- - spec/support/rails/config/routes.rb
155
- - spec/support/rails/db/schema.rb
156
- - spec/support/rails/log/.gitignore
157
- - spec/support/rails/public/favicon.ico
158
139
  homepage: https://github.com/TwilightCoders/quick_count
159
140
  licenses:
160
141
  - MIT
@@ -177,17 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
158
  version: '0'
178
159
  requirements: []
179
160
  rubyforge_project:
180
- rubygems_version: 2.7.5
161
+ rubygems_version: 2.6.14.1
181
162
  signing_key:
182
163
  specification_version: 4
183
164
  summary: Quickly get an accurate count estimation for large tables.
184
- test_files:
185
- - spec/quick_count_spec.rb
186
- - spec/spec_helper.rb
187
- - spec/support/rails/app/models/post.rb
188
- - spec/support/rails/app/models/user.rb
189
- - spec/support/rails/config/database.yml
190
- - spec/support/rails/config/routes.rb
191
- - spec/support/rails/db/schema.rb
192
- - spec/support/rails/log/.gitignore
193
- - spec/support/rails/public/favicon.ico
165
+ test_files: []
data/.gitignore DELETED
@@ -1,75 +0,0 @@
1
- # See http://help.github.com/ignore-files/ for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile ~/.gitignore_global
6
-
7
- # Database config and secrets
8
- /config/database.yml
9
- /config/secrets.yml
10
-
11
- # Ignore bundler config
12
- /.bundle
13
-
14
- # Ignore the default SQLite database.
15
- /db/*.sqlite3
16
-
17
- # Ignore all logfiles and tempfiles.
18
- /log/*.log
19
- /tmp
20
- /db/structure.sql
21
- /doc/app/*
22
- /vendor/cldr/*
23
- /public/uploads/*
24
- /public/photo/*
25
- /public/test/*
26
- /test/assets/*
27
- /spec/assets/*
28
- /public/assets/**
29
- .powenv
30
- .rvmrc
31
- .env
32
- .ruby-version
33
-
34
- # Compiled source #
35
- ###################
36
- /pkg
37
- *.com
38
- *.class
39
- *.dll
40
- *.exe
41
- *.o
42
- *.so
43
-
44
- # Packages #
45
- ############
46
- # it's better to unpack these files and commit the raw source
47
- # git has its own built in compression methods
48
- *.7z
49
- *.dmg
50
- *.gz
51
- *.iso
52
- *.jar
53
- *.rar
54
- *.tar
55
- *.zip
56
-
57
- # Logs and databases #
58
- ######################
59
- *.log
60
- *.sql
61
- *.sqlite
62
-
63
- # OS generated files #
64
- ######################
65
- .DS_Store
66
- .DS_Store?
67
- ._*
68
- .Spotlight-V100
69
- .Trashes
70
- Icon?
71
- ehthumbs.db
72
- Thumbs.db
73
- /Gemfile.lock
74
- /coverage
75
- /.editorconfig
data/.travis.yml DELETED
@@ -1,29 +0,0 @@
1
- language: ruby
2
-
3
- sudo: false
4
-
5
- cache: bundler
6
-
7
- before_script:
8
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
- - chmod +x ./cc-test-reporter
10
- - ./cc-test-reporter before-build
11
-
12
- script:
13
- - bundle exec rspec
14
-
15
- after_script:
16
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
17
-
18
- addons:
19
- postgresql: "9.3"
20
-
21
- rvm:
22
- - 2.5
23
- - 2.4
24
- - 2.3
25
-
26
- gemfile:
27
- - gemfiles/activerecord-5.1.Gemfile
28
- - gemfiles/activerecord-5.0.Gemfile
29
- - gemfiles/activerecord-4.2.Gemfile
data/Gemfile DELETED
@@ -1,19 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :test do
6
-
7
- # Generates coverage stats of specs
8
- gem 'simplecov'
9
-
10
- # Publishes coverage to codeclimate
11
- gem 'codeclimate-test-reporter'
12
-
13
- gem 'rspec'
14
-
15
- gem 'database_cleaner'
16
-
17
- gem 'combustion'
18
-
19
- end
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,3 +0,0 @@
1
- eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
-
3
- gem 'activerecord', '~> 4.0.0'
@@ -1,3 +0,0 @@
1
- eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
-
3
- gem 'activerecord', '~> 4.1.0'
@@ -1,3 +0,0 @@
1
- eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
-
3
- gem 'activerecord', '~> 4.2.0'
@@ -1,3 +0,0 @@
1
- eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
-
3
- gem 'activerecord', '~> 5.0.0'
@@ -1,3 +0,0 @@
1
- eval_gemfile File.join(File.dirname(__FILE__), "../Gemfile")
2
-
3
- gem 'activerecord', '~> 5.1.0'
@@ -1,15 +0,0 @@
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
@@ -1,20 +0,0 @@
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/quick_count.gemspec DELETED
@@ -1,43 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'quick_count/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'quick_count'
8
- spec.version = QuickCount::VERSION
9
- spec.authors = ['Dale Stevens']
10
- spec.email = ['dale@twilightcoders.net']
11
-
12
- spec.summary = 'Quickly get an accurate count estimation for large tables.'
13
- spec.description = 'Installs two database functions, `quick_count` and `count_estimate` for getting count estimations on large tables'
14
- spec.homepage = "https://github.com/TwilightCoders/quick_count"
15
- spec.license = 'MIT'
16
-
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- if spec.respond_to?(:metadata)
20
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
- else
22
- raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
- end
24
-
25
- spec.files = `git ls-files -z`.split("\x0")
26
- spec.bindir = 'bin'
27
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
29
- spec.require_paths = ['lib', 'spec']
30
-
31
- rails_versions = ['>= 4', '< 6']
32
- spec.required_ruby_version = '>= 2.0'
33
-
34
- spec.add_runtime_dependency 'pg', '~> 0'
35
- spec.add_runtime_dependency 'activerecord', rails_versions
36
- spec.add_runtime_dependency 'railties', rails_versions
37
-
38
- spec.add_development_dependency 'pry-byebug', '~> 3'
39
- spec.add_development_dependency 'bundler', '~> 1.3'
40
- spec.add_development_dependency 'rake', '~> 12.0'
41
- spec.add_development_dependency 'combustion', '~> 0.7'
42
-
43
- end
@@ -1,18 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe QuickCount do
4
- it "is present in models" do
5
- expect(Post).to respond_to(:quick_count)
6
- expect(Post.all).to respond_to(:count_estimate)
7
- end
8
-
9
- it "returns the correct count" do
10
- expect(Post.quick_count).to be(0)
11
- expect(Post.all.count_estimate).to be > 0
12
- end
13
-
14
- it "root has the right value" do
15
- expect(QuickCount.root).not_to be_nil
16
- end
17
-
18
- end
data/spec/spec_helper.rb DELETED
@@ -1,29 +0,0 @@
1
- ENV['RAILS_ENV'] = 'test'
2
-
3
- require 'database_cleaner'
4
- require 'combustion'
5
-
6
- require 'simplecov'
7
- SimpleCov.start do
8
- add_filter 'spec'
9
- end
10
-
11
- Combustion.path = 'spec/support/rails'
12
- Combustion.initialize! :active_record
13
-
14
- schema = "quick_count"
15
-
16
- RSpec.configure do |config|
17
- config.order = "random"
18
-
19
- config.before(:suite) do
20
- ActiveRecord::Base.connection.execute("CREATE SCHEMA #{schema}")
21
- QuickCount.install(schema: schema)
22
- end
23
-
24
- config.after(:suite) do
25
- QuickCount.uninstall(schema: schema)
26
- ActiveRecord::Base.connection.execute("DROP SCHEMA #{schema}")
27
- end
28
-
29
- end
@@ -1,3 +0,0 @@
1
- class Post < ::ActiveRecord::Base
2
- belongs_to :user
3
- end
@@ -1,3 +0,0 @@
1
- class User < ::ActiveRecord::Base
2
- has_many :posts
3
- end
@@ -1,5 +0,0 @@
1
- test:
2
- adapter: postgresql
3
- encoding: unicode
4
- database: quick_count-test
5
- schema_search_path: "quick_count,public"
@@ -1,3 +0,0 @@
1
- Rails.application.routes.draw do
2
- #
3
- end
@@ -1,14 +0,0 @@
1
- ActiveRecord::Schema.define do
2
- self.verbose = false
3
-
4
- create_table :users do |t|
5
- t.string :name
6
- end
7
-
8
- create_table :posts do |t|
9
- t.integer :user_id
10
- t.string :title
11
- t.timestamps
12
- end
13
-
14
- end
@@ -1 +0,0 @@
1
- *.log
File without changes