klastera 1.3.1 → 1.3.2

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
  SHA256:
3
- metadata.gz: a8ffbcdd772da4880e6fac3a2fa9165754a873673afb5f2108161d099e634622
4
- data.tar.gz: 8541bb3c9c26b8e0084e42b91ef9262b443dbaf1250e4bd209a2fde9db6d92a9
3
+ metadata.gz: 4fe09e51ca6d275a070d368cd49d916ff2ad2b02f2c06e2afcec708bda66ef88
4
+ data.tar.gz: 03d542c381f4eaefa9079d8ca47c33c787658faa0cce87127225f52a069bbd46
5
5
  SHA512:
6
- metadata.gz: e43f85ef19e054e32274ad4c5c99db112333c76fa831383e72f3e0f7d7ad312d5b48519c33794a46ad3148dd4d50cca62117620e756b12933f0889a9891ad631
7
- data.tar.gz: dc98ab10fc1588bec841af4b1e3a4caee5b976986e8023b7528c70190ee2b27fb2e230855773aaa1fcf1a28392380b9f63d186b9165e4f5704acf2631cd3d40f
6
+ metadata.gz: 88d80a8309499a0b61d96a44d3a297fcb87fe9352d46021a7e415a66bb1e2e4776400888396478deacb9108c861bfe69755477e23f9d43ed4273b2ce98206bf5
7
+ data.tar.gz: 836a8472f3a71fda307b77c4c7c69e038bb9c01f2d364b6fb98817cc096960dca2a4ee7d8eb8735b83fbb1a67bd31e4f168f45871fa79362d6e600ac10aed307
@@ -114,40 +114,30 @@ module Klastera
114
114
  end
115
115
 
116
116
 
117
- # Untested version for more optimized queries
117
+ # Optimized version of cluster_scope!
118
118
  #
119
- def __cluster_scope!(scope,user,organization,cluster_id=nil,same_scope:false)
119
+ def same_cluster_scope!(scope,user,organization,cluster_id=nil)
120
120
  scope_klass = scope_class(scope)
121
121
  if organization.is_in_cluster_mode?
122
- scope_klass = scope_klass.includes(:organization)
122
+ scope_klass = scope_klass.eager_load(:organization,cluster_entities: :cluster)
123
123
 
124
124
  if cluster_id.present?
125
125
  cluster_ids = cluster_id.is_a?(Array) ? cluster_id : [cluster_id]
126
126
  else
127
127
  clusters = cluster_of!(user,organization)
128
- cluster_ids = clusters.map(&:id).compact
128
+ cluster_ids = clusters.map(&:id).compact.sort
129
129
  end
130
130
 
131
131
  scope_klass = scope_klass.select("DISTINCT ON (#{scope.table_name}.id) #{scope.table_name}.id, #{scope.table_name}.*, clusters.*")
132
132
 
133
- if organization.required_suborganization_mode?
134
- scope_klass = scope_klass.includes(cluster_entities: :cluster).where( cluster_entities: { cluster_id: cluster_ids } )
133
+ if organization.required_suborganization_mode?# || cluster_id # If cluster_id is passed NULL clusters are expected, rigth?
134
+ scope_klass = scope_klass.where( cluster_entities: { cluster_id: cluster_ids } )
135
135
  else
136
136
  or_these_cluster_ids = cluster_ids.present? ? " OR cluster_entities.cluster_id IN (#{cluster_ids.join(",")})" : ""
137
- scope_klass = scope_klass.joins("
138
- LEFT OUTER JOIN cluster_entities
139
- ON entity_id = #{scope.table_name}.id
140
- AND entity_type = '#{scope}'
141
- ").joins("
142
- LEFT OUTER JOIN clusters
143
- ON clusters.id = cluster_entities.cluster_id
144
- ").where("cluster_entities.id IS NULL#{or_these_cluster_ids}")
145
- end
146
- # Provisional fix to avoid unresolved SQL clashes with the main application due to DISTINCT ON clause
147
- unless same_scope
148
- scope_klass = scope_class(scope).eager_load(:cluster_entities).where(id: scope_klass.map(&:id))
137
+ scope_klass = scope_klass.where("cluster_entities.id IS NULL#{or_these_cluster_ids}")
149
138
  end
150
139
  end
140
+
151
141
  scope_klass.where(organization_id: organization)
152
142
  end
153
143
 
@@ -245,8 +235,8 @@ module Klastera
245
235
  Klastera.cluster_scope!(scope, cluster_user, cluster_organization, cluster_id)
246
236
  end
247
237
 
248
- def __cluster_scope(scope,cluster_id=nil,same_scope:false)
249
- Klastera.__cluster_scope!(scope, cluster_user, cluster_organization, cluster_id, same_scope: same_scope)
238
+ def same_cluster_scope(scope,cluster_id=nil)
239
+ Klastera.same_cluster_scope!(scope, cluster_user, cluster_organization, cluster_id)
250
240
  end
251
241
 
252
242
  def cluster_of_my_own
@@ -1,3 +1,3 @@
1
1
  module Klastera
2
- VERSION = "1.3.1"
2
+ VERSION = "1.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klastera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gino Barahona
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails