activerecord-precounter 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -20
- data/lib/active_record/precounter/version.rb +1 -1
- data/lib/active_record/precounter.rb +10 -4
- 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: bf992b2001ae6c7bf6ada58116ae081228ab07c6
|
4
|
+
data.tar.gz: 0762cdbd9a2ed0924a19cdd9835773250cf5bcba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 365ef8fe72218325265a8a3b563c325de40f81d3c65097798a59fdaa4e504cd10bc74d4888480f8202da17d9c3e9ccc4cce03a5ff288e283469cc5e1e9b57846
|
7
|
+
data.tar.gz: a56f1bf870d6c334816806bd6712db25f1f6080c5705fbb5104724b8802e192c6580f244436a0ef7012d1a54fdad82b958a21fdc71497a40416c9264dd37a69f
|
data/.travis.yml
CHANGED
@@ -7,27 +7,9 @@ branches:
|
|
7
7
|
- master
|
8
8
|
matrix:
|
9
9
|
include:
|
10
|
-
- rvm: 2.1.10
|
11
|
-
env: TASK=test ARCONN=mysql2
|
12
|
-
gemfile: ci/Gemfile.activerecord-4.2.x
|
13
|
-
- rvm: 2.2.7
|
14
|
-
env: TASK=test ARCONN=mysql2
|
15
|
-
gemfile: ci/Gemfile.activerecord-5.1.x
|
16
|
-
- rvm: 2.3.4
|
17
|
-
env: TASK=test ARCONN=mysql2
|
18
|
-
gemfile: ci/Gemfile.activerecord-5.1.x
|
19
|
-
- rvm: 2.4.1
|
20
|
-
env: TASK=test ARCONN=mysql2
|
21
|
-
gemfile: ci/Gemfile.activerecord-4.2.x
|
22
|
-
- rvm: 2.4.1
|
23
|
-
env: TASK=test ARCONN=mysql2
|
24
|
-
gemfile: ci/Gemfile.activerecord-5.0.x
|
25
|
-
- rvm: 2.4.1
|
26
|
-
env: TASK=test ARCONN=sqlite3
|
27
|
-
gemfile: ci/Gemfile.activerecord-5.1.x
|
28
10
|
- rvm: 2.4.1
|
29
|
-
env: TASK=
|
11
|
+
env: TASK=spec ARCONN=sqlite3
|
30
12
|
gemfile: ci/Gemfile.activerecord-5.1.x
|
31
13
|
- rvm: 2.4.1
|
32
|
-
env: TASK=
|
14
|
+
env: TASK=spec ARCONN=postgresql
|
33
15
|
gemfile: ci/Gemfile.activerecord-5.1.x
|
@@ -13,7 +13,7 @@ module ActiveRecord
|
|
13
13
|
# @return [Array<ActiveRecord::Base>]
|
14
14
|
def precount(*association_names)
|
15
15
|
records = @relation.to_a
|
16
|
-
return if records.empty?
|
16
|
+
return [] if records.empty?
|
17
17
|
|
18
18
|
association_names.each do |association_name|
|
19
19
|
association_name = association_name.to_s
|
@@ -26,9 +26,15 @@ module ActiveRecord
|
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
29
|
-
count_by_id = reflection.
|
30
|
-
|
31
|
-
|
29
|
+
count_by_id = if reflection.has_scope?
|
30
|
+
reflection.scope_for(reflection.klass.where(reflection.inverse_of.name => @relation)).group(
|
31
|
+
reflection.inverse_of.foreign_key
|
32
|
+
).count
|
33
|
+
else
|
34
|
+
reflection.klass.where(reflection.inverse_of.name => @relation).group(
|
35
|
+
reflection.inverse_of.foreign_key
|
36
|
+
).count
|
37
|
+
end
|
32
38
|
|
33
39
|
writer = define_count_accessor(records.first, association_name)
|
34
40
|
records.each do |record|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-precounter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.6.13
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Yet Another N+1 COUNT Query Killer for ActiveRecord
|