activerecord-precount 0.6.2 → 0.6.3
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/.travis.yml +9 -6
- data/CHANGELOG.md +36 -6
- data/lib/active_record/precount/preloader_extension.rb +1 -1
- data/lib/active_record/precount/version.rb +1 -1
- data/test/cases/associations/precount_test.rb +9 -0
- data/test/cases/test_case.rb +17 -0
- data/test/models/tweet.rb +1 -0
- 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: bf58363c7ce0affb2cbb1a39d19e348fc1d8924c
|
4
|
+
data.tar.gz: 2872afab02a9bc30db92dc0dacf225546109685a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 796a87639f40c88f97d91c4f5f42b96870e81a14986faf0b0404367678cc827b4c6a9ea0422e43c502a5ee0b33880a741e74ec96fccf4194bb65c8fc3230cd60
|
7
|
+
data.tar.gz: bef1cc5f6a82d932a2d9560e483ecd2e8a31af762fa8df69eaff345b42c46eb638a8f90245893ad3505058dfee359fdb8034e56a02146e4a525e284cffed15d2
|
data/.travis.yml
CHANGED
@@ -10,22 +10,25 @@ matrix:
|
|
10
10
|
- rvm: 2.1.10
|
11
11
|
env: TASK=test ARCONN=mysql2
|
12
12
|
gemfile: ci/Gemfile.activerecord-4.2.x
|
13
|
-
- rvm: 2.2.
|
13
|
+
- rvm: 2.2.6
|
14
14
|
env: TASK=test ARCONN=mysql2
|
15
15
|
gemfile: ci/Gemfile.activerecord-5.0.x
|
16
|
-
- rvm: 2.3.
|
16
|
+
- rvm: 2.3.3
|
17
|
+
env: TASK=test ARCONN=mysql2
|
18
|
+
gemfile: ci/Gemfile.activerecord-5.0.x
|
19
|
+
- rvm: 2.4.0
|
17
20
|
env: TASK=test ARCONN=mysql2
|
18
21
|
gemfile: ci/Gemfile.activerecord-4.2.x
|
19
|
-
- rvm: 2.
|
22
|
+
- rvm: 2.4.0
|
20
23
|
env: TASK=test ARCONN=sqlite3
|
21
24
|
gemfile: ci/Gemfile.activerecord-5.0.x
|
22
|
-
- rvm: 2.
|
25
|
+
- rvm: 2.4.0
|
23
26
|
env: TASK=test ARCONN=mysql2
|
24
27
|
gemfile: ci/Gemfile.activerecord-5.0.x
|
25
|
-
- rvm: 2.
|
28
|
+
- rvm: 2.4.0
|
26
29
|
env: TASK=test ARCONN=postgresql
|
27
30
|
gemfile: ci/Gemfile.activerecord-5.0.x
|
28
|
-
- rvm: 2.
|
31
|
+
- rvm: 2.4.0
|
29
32
|
env: TASK=benchmark ARCONN=mysql2
|
30
33
|
gemfile: ci/Gemfile.activerecord-5.0.x
|
31
34
|
allow_failures:
|
data/CHANGELOG.md
CHANGED
@@ -1,25 +1,55 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v0.6.
|
3
|
+
## [v0.6.2](https://github.com/k0kubun/activerecord-precount/tree/v0.6.2) (2016-11-02)
|
4
|
+
[Full Changelog](https://github.com/k0kubun/activerecord-precount/compare/v0.6.1...v0.6.2)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- NoMethodError: undefined method `destroyed?' on saving instance [\#19](https://github.com/k0kubun/activerecord-precount/issues/19)
|
9
|
+
- Support association's :class\_name option set to a constant [\#18](https://github.com/k0kubun/activerecord-precount/issues/18)
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Add patch for ActiveRecord::AutosaveAssociation [\#20](https://github.com/k0kubun/activerecord-precount/pull/20) ([takashi](https://github.com/takashi))
|
14
|
+
|
15
|
+
## [v0.6.1](https://github.com/k0kubun/activerecord-precount/tree/v0.6.1) (2016-06-04)
|
4
16
|
[Full Changelog](https://github.com/k0kubun/activerecord-precount/compare/v0.6.0...v0.6.1)
|
5
17
|
|
6
|
-
|
18
|
+
**Closed issues:**
|
19
|
+
|
20
|
+
- Count method performance issue [\#9](https://github.com/k0kubun/activerecord-precount/issues/9)
|
21
|
+
- Vendor ActiveRecord tests [\#2](https://github.com/k0kubun/activerecord-precount/issues/2)
|
22
|
+
|
23
|
+
**Merged pull requests:**
|
24
|
+
|
25
|
+
- Support polymorphic precount [\#17](https://github.com/k0kubun/activerecord-precount/pull/17) ([k0kubun](https://github.com/k0kubun))
|
26
|
+
- Refactoring [\#16](https://github.com/k0kubun/activerecord-precount/pull/16) ([k0kubun](https://github.com/k0kubun))
|
7
27
|
|
8
28
|
## [v0.6.0](https://github.com/k0kubun/activerecord-precount/tree/v0.6.0) (2016-06-02)
|
9
29
|
[Full Changelog](https://github.com/k0kubun/activerecord-precount/compare/v0.5.1...v0.6.0)
|
10
30
|
|
11
|
-
|
12
|
-
|
31
|
+
**Closed issues:**
|
32
|
+
|
33
|
+
- Rails 5 support [\#13](https://github.com/k0kubun/activerecord-precount/issues/13)
|
34
|
+
|
35
|
+
**Merged pull requests:**
|
36
|
+
|
37
|
+
- Rails 5 [\#14](https://github.com/k0kubun/activerecord-precount/pull/14) ([k0kubun](https://github.com/k0kubun))
|
38
|
+
- Support Ruby 2.3.0 [\#12](https://github.com/k0kubun/activerecord-precount/pull/12) ([k0kubun](https://github.com/k0kubun))
|
13
39
|
|
14
40
|
## [v0.5.1](https://github.com/k0kubun/activerecord-precount/tree/v0.5.1) (2015-09-09)
|
15
41
|
[Full Changelog](https://github.com/k0kubun/activerecord-precount/compare/v0.5.0...v0.5.1)
|
16
42
|
|
43
|
+
**Merged pull requests:**
|
44
|
+
|
17
45
|
- Support an association with a scope [\#10](https://github.com/k0kubun/activerecord-precount/pull/10) ([tkawa](https://github.com/tkawa))
|
18
46
|
|
19
47
|
## [v0.5.0](https://github.com/k0kubun/activerecord-precount/tree/v0.5.0) (2015-02-01)
|
20
48
|
[Full Changelog](https://github.com/k0kubun/activerecord-precount/compare/v0.4.3...v0.5.0)
|
21
49
|
|
22
|
-
|
50
|
+
**Closed issues:**
|
51
|
+
|
52
|
+
- Is it possible to eager\_load count\_loader association? [\#1](https://github.com/k0kubun/activerecord-precount/issues/1)
|
23
53
|
|
24
54
|
## [v0.4.3](https://github.com/k0kubun/activerecord-precount/tree/v0.4.3) (2015-01-31)
|
25
55
|
[Full Changelog](https://github.com/k0kubun/activerecord-precount/compare/v0.4.2...v0.4.3)
|
@@ -84,4 +114,4 @@
|
|
84
114
|
|
85
115
|
|
86
116
|
|
87
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
117
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
@@ -25,7 +25,7 @@ module ActiveRecord
|
|
25
25
|
|
26
26
|
def query_scope(ids)
|
27
27
|
key = model.reflections[reflection.name.to_s.sub(/_count\z/, '')].foreign_key
|
28
|
-
scope.where(key => ids).group(key).count(key)
|
28
|
+
scope.reorder(nil).where(key => ids).group(key).count(key)
|
29
29
|
end
|
30
30
|
|
31
31
|
def build_scope
|
@@ -50,6 +50,15 @@ class PrecountTest < ActiveRecord::CountLoader::TestCase
|
|
50
50
|
assert_equal(expected, Tweet.precount(:my_favs).map(&:my_favs_count))
|
51
51
|
end
|
52
52
|
|
53
|
+
def test_precount_has_many_with_ordered_association_conforms_to_mysql_only_full_group_by
|
54
|
+
with_mysql_sql_mode('ONLY_FULL_GROUP_BY') do
|
55
|
+
expected = Tweet.all.map { |t| t.ordered_favorites.count }
|
56
|
+
assert_equal(expected, Tweet.all.map(&:ordered_favorites_count))
|
57
|
+
assert_equal(expected, Tweet.precount(:ordered_favorites).map { |t| t.ordered_favorites.count })
|
58
|
+
assert_equal(expected, Tweet.precount(:ordered_favorites).map(&:ordered_favorites_count))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
53
62
|
def test_polymorphic_precount
|
54
63
|
expected = Tweet.all.map { |t| t.notifications.count }
|
55
64
|
assert_equal(expected, Tweet.precount(:notifications).map(&:notifications_count))
|
data/test/cases/test_case.rb
CHANGED
@@ -46,6 +46,23 @@ module ActiveRecord::CountLoader
|
|
46
46
|
options.reverse_merge! ignore_none: true
|
47
47
|
assert_queries(0, options, &block)
|
48
48
|
end
|
49
|
+
|
50
|
+
def with_mysql_sql_mode(sql_mode)
|
51
|
+
connection = ActiveRecord::Base.connection
|
52
|
+
|
53
|
+
if connection.adapter_name == 'Mysql2'
|
54
|
+
original_sql_mode = connection.execute('SELECT @@SESSION.sql_mode').first.first
|
55
|
+
connection.execute("SET @@SESSION.sql_mode = '#{original_sql_mode},#{sql_mode}'")
|
56
|
+
|
57
|
+
begin
|
58
|
+
yield
|
59
|
+
ensure
|
60
|
+
connection.execute("SET @@SESSION.sql_mode = '#{original_sql_mode}'")
|
61
|
+
end
|
62
|
+
else
|
63
|
+
yield
|
64
|
+
end
|
65
|
+
end
|
49
66
|
end
|
50
67
|
|
51
68
|
class SQLCounter
|
data/test/models/tweet.rb
CHANGED
@@ -3,5 +3,6 @@ class Tweet < ActiveRecord::Base
|
|
3
3
|
has_many :favs, class_name: 'Favorite'
|
4
4
|
has_many :my_favorites, -> { where(user_id: 1) }, class_name: 'Favorite', count_loader: true
|
5
5
|
has_many :my_favs, -> { where(user_id: 1) }, class_name: 'Favorite'
|
6
|
+
has_many :ordered_favorites, -> { order(:id) }, class_name: 'Favorite', count_loader: true
|
6
7
|
has_many :notifications, as: :notifiable, foreign_key: :notifiable_id
|
7
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-precount
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -318,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
318
318
|
version: '0'
|
319
319
|
requirements: []
|
320
320
|
rubyforge_project:
|
321
|
-
rubygems_version: 2.5.
|
321
|
+
rubygems_version: 2.5.2
|
322
322
|
signing_key:
|
323
323
|
specification_version: 4
|
324
324
|
summary: N+1 count query killer for ActiveRecord
|