rails_select_on_includes 0.5.0 → 0.5.1

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
2
  SHA1:
3
- metadata.gz: fb99c7d08c8db00bef1394aac2ac055df1707be5
4
- data.tar.gz: 02591eb16f17bb61ba429b4a6d4eb6fad665bfa3
3
+ metadata.gz: 443283f4904c4f4329a5a32983f4defe8a63a5e3
4
+ data.tar.gz: 53601f7583dc63c766b8182c0d6b485bd6295cfe
5
5
  SHA512:
6
- metadata.gz: 7639db4cbef9c67f0f5f04a5034709d2317dda111661f0519c5e5baefc60089edae19d32f844ec7d4293d0f826d878d9d2be3168625709aded1ddd7b8cc90405
7
- data.tar.gz: c07bd198ed1cd3eb81d65bcdaa5ddcc25ebc541a505511941ab5ea0cfbdde981e3bcdcbcdde904eae7ac0e6a4696e86dab91b0550068db6793b441ea190446c2
6
+ metadata.gz: be9bd630a495fd6874d118f2cc06959e18ae792775ede4f0ff44a44d0f5a783606e8a2f47ced47279f01e1f66b7ec5410d58b585da2bec1fbc6532e033e97387
7
+ data.tar.gz: 7f64aa60dfbfc950696ff200441941482bab8494ecc4d8b167cf2a0207db4f1a5fb9b708760db83bc87d1e6786c2db515e8093d2a9c98a72ab037f6f77f5127d
@@ -4,7 +4,6 @@ require 'active_support/core_ext/string/filters'
4
4
  module ActiveRecord
5
5
  module Associations
6
6
  class JoinDependency # :nodoc:
7
-
8
7
  class Aliases # :nodoc:
9
8
  def initialize(tables)
10
9
  @tables = tables
@@ -51,9 +50,49 @@ module ActiveRecord
51
50
  some_hash.values.map{ |value| value.is_a?(Hash) ? flatten_hash_values( value ) : value }.flatten
52
51
  end
53
52
  end
53
+
54
+ class JoinPart
55
+ def instantiate(row, aliases, column_types = {}, &block)
56
+ base_klass.instantiate(extract_record(row, aliases), column_types, &block)
57
+ end
58
+ end
59
+
60
+ def instantiate(result_set, aliases)
61
+ primary_key = aliases.column_alias(join_root, join_root.primary_key)
62
+
63
+ seen = Hash.new { |i, object_id|
64
+ i[object_id] = Hash.new { |j, child_class|
65
+ j[child_class] = {}
66
+ }
67
+ }
68
+
69
+ model_cache = Hash.new { |h,klass| h[klass] = {} }
70
+ parents = model_cache[join_root]
71
+ column_aliases = aliases.column_aliases join_root
72
+
73
+ message_bus = ActiveSupport::Notifications.instrumenter
74
+
75
+ payload = {
76
+ record_count: result_set.length,
77
+ class_name: join_root.base_klass.name
78
+ }
79
+
80
+ message_bus.instrument('instantiation.active_record', payload) do
81
+ result_set.each { |row_hash|
82
+ parent_key = primary_key ? row_hash[primary_key] : row_hash
83
+ # DISTINCTION PART > join_root.instantiate(row_hash, column_aliases, result_set.column_types )
84
+ # PREVIOUS join_root.instantiate(row_hash, column_aliases )
85
+ parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, result_set.column_types )
86
+ construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
87
+ }
88
+ end
89
+ parents.values
90
+ end
91
+
54
92
  end
55
93
  end
56
94
  end
95
+
57
96
  module ActiveRecord
58
97
  module FinderMethods
59
98
 
@@ -81,7 +120,7 @@ module ActiveRecord
81
120
  else
82
121
  arel = relation.arel
83
122
  rows = connection.select_all(arel, 'SQL', relation.bound_attributes)
84
- #DISTINCTION IS HERE:
123
+ #1 DISTINCTION IS HERE:
85
124
  # now we gently mokey-patching existing column aliases with select values
86
125
  aliases.update_aliases_to_select_values(values[:select]) unless values[:select].blank?
87
126
 
@@ -1,3 +1,3 @@
1
1
  module RailsSelectOnIncludes
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_select_on_includes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-06 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord