eager_group 0.8.0 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/MIT-LICENSE +20 -0
- data/lib/eager_group/preloader.rb +14 -22
- data/lib/eager_group/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5370e57578e725513b391777f1a86e3b1d7560bc596a08b005110d3220d43325
|
4
|
+
data.tar.gz: b4987065f8781190983f2b92a84db5ea7e248f43290763ba483d52ec472cb1e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 172290ed5e79c34139cdc35976f22e612e225e39f6b417f07f86696970f28969f058c59189e683d9ca299d5d61643dbdbf8220648889f7e4bbcb66cb30f68d7e
|
7
|
+
data.tar.gz: 91577037162ebb062b8939c02fc2aa66e4fdf1e891fb6e20ffd199d7e80879c38f20ae4fc4cc95ae32c7f16ab90377816ed42dc215dd0cd92fad9ce01f9450ea
|
data/CHANGELOG.md
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 - 2022 Richard Huang (flyerhzm@gmail.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -31,28 +31,20 @@ module EagerGroup
|
|
31
31
|
association_class = reflection.klass
|
32
32
|
association_class = association_class.instance_exec(*arguments, &definition.scope) if definition.scope
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
)
|
48
|
-
.group(foreign_key)
|
49
|
-
.send(definition.aggregation_function, definition.column_name)
|
50
|
-
else
|
51
|
-
aggregate_hash =
|
52
|
-
association_class.where(reflection.foreign_key => record_ids).where(polymophic_as_condition(reflection))
|
53
|
-
.group(reflection.foreign_key)
|
54
|
-
.send(definition.aggregation_function, definition.column_name)
|
55
|
-
end
|
34
|
+
foreign_key, aggregate_hash =
|
35
|
+
if reflection.is_a?(ActiveRecord::Reflection::HasAndBelongsToManyReflection)
|
36
|
+
["#{reflection.join_table}.#{reflection.foreign_key}", @klass.joins(reflection.name)]
|
37
|
+
elsif reflection.through_reflection
|
38
|
+
[
|
39
|
+
"#{reflection.through_reflection.name}.#{reflection.through_reflection.foreign_key}",
|
40
|
+
@klass.joins(reflection.name)
|
41
|
+
]
|
42
|
+
else
|
43
|
+
[reflection.foreign_key, association_class]
|
44
|
+
end
|
45
|
+
aggregate_hash =
|
46
|
+
aggregate_hash.where(foreign_key => record_ids).where(polymophic_as_condition(reflection)).group(foreign_key)
|
47
|
+
.send(definition.aggregation_function, definition.column_name)
|
56
48
|
if definition.need_load_object
|
57
49
|
aggregate_objects = reflection.klass.find(aggregate_hash.values).each_with_object({}) { |o, h| h[o.id] = o }
|
58
50
|
aggregate_hash.keys.each { |key| aggregate_hash[key] = aggregate_objects[aggregate_hash[key]] }
|
data/lib/eager_group/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eager_group
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- ".travis.yml"
|
135
135
|
- CHANGELOG.md
|
136
136
|
- Gemfile
|
137
|
+
- MIT-LICENSE
|
137
138
|
- README.md
|
138
139
|
- Rakefile
|
139
140
|
- benchmark.rb
|
@@ -149,7 +150,7 @@ homepage: https://github.com/flyerhzm/eager_group
|
|
149
150
|
licenses:
|
150
151
|
- MIT
|
151
152
|
metadata: {}
|
152
|
-
post_install_message:
|
153
|
+
post_install_message:
|
153
154
|
rdoc_options: []
|
154
155
|
require_paths:
|
155
156
|
- lib
|
@@ -164,8 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
165
|
- !ruby/object:Gem::Version
|
165
166
|
version: '0'
|
166
167
|
requirements: []
|
167
|
-
rubygems_version: 3.
|
168
|
-
signing_key:
|
168
|
+
rubygems_version: 3.3.7
|
169
|
+
signing_key:
|
169
170
|
specification_version: 4
|
170
171
|
summary: Fix n+1 aggregate sql functions
|
171
172
|
test_files: []
|