klastera 1.5.5 → 1.5.5.1
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/app/models/klastera/concerns/clusterizable.rb +3 -3
- data/lib/klastera/version.rb +1 -1
- data/lib/klastera.rb +24 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01b3c7e4c25fc9bfa852d34304d0f0cb12b832da7565375eb9e4cb5f4abc2566
|
4
|
+
data.tar.gz: 5ccc41a05b2e0ae3a5e8f4b16176be63ec752b0a112f3d8c1276bd403b591386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07c277261a1ff65e45ca4413587c3ca51952e497176d2a3e29e361c955a51e2d6d77bd4ae5ee8946e8981d56fa1ec756eed81b12e454f623732e5505a7a09349
|
7
|
+
data.tar.gz: 6f1097125134ab6a528c165df1396697c4c83db96bbfa2265b19f04025a2f72fe5a4e423dcf2a49f23fb0fcb75156911471190e332fae94cd962e2331d0042b7
|
@@ -33,7 +33,7 @@ module Klastera::Concerns::Clusterizable
|
|
33
33
|
def clusters_string_separated_by(separator, attribute=:name)
|
34
34
|
# Use Rails cache for frequently accessed cluster strings
|
35
35
|
cache_key = [self.cache_key_with_version, :clusters_string, separator, attribute]
|
36
|
-
|
36
|
+
|
37
37
|
Rails.cache.fetch(cache_key, expires_in: 30.minutes) do
|
38
38
|
Klastera.entity_clusters_string_list!(
|
39
39
|
cluster_entities, separator, attribute
|
@@ -74,9 +74,9 @@ module Klastera::Concerns::Clusterizable
|
|
74
74
|
##
|
75
75
|
def preload_clusters(collection)
|
76
76
|
return collection if collection.empty?
|
77
|
-
|
77
|
+
|
78
78
|
ActiveRecord::Associations::Preloader.new.preload(
|
79
|
-
collection,
|
79
|
+
collection,
|
80
80
|
cluster_entities: :cluster
|
81
81
|
)
|
82
82
|
collection
|
data/lib/klastera/version.rb
CHANGED
data/lib/klastera.rb
CHANGED
@@ -53,10 +53,10 @@ module Klastera
|
|
53
53
|
if allowed_cluster_ids.is_a?(Array)
|
54
54
|
_cluster_entities.select!{|ce| allowed_cluster_ids.include?(ce.cluster_id)}
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# Performance optimization: Use preloaded data when available
|
58
58
|
if cluster_entities.respond_to?(:loaded?) && cluster_entities.loaded? &&
|
59
|
-
|
59
|
+
_cluster_entities.all? { |ce| ce.association(:cluster).loaded? }
|
60
60
|
# Use in-memory data (much faster)
|
61
61
|
_cluster_entities.map do |ce|
|
62
62
|
ce.cluster.try(attribute)
|
@@ -64,13 +64,29 @@ module Klastera
|
|
64
64
|
else
|
65
65
|
# Fallback to original method with database query
|
66
66
|
# But use a single query instead of N+1
|
67
|
-
|
67
|
+
|
68
|
+
cluster_ids = _cluster_entities.filter_map(&:cluster_id).uniq
|
68
69
|
return "" if cluster_ids.empty?
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
|
71
|
+
records = ::Cluster.where(id: cluster_ids).pluck(:id, attribute)
|
72
|
+
return "" if records.empty?
|
73
|
+
|
74
|
+
# clusters_hash = if records.any? && !records.first.is_a?(Array)
|
75
|
+
# records.map { |id| [id, id] }.to_h
|
76
|
+
# else
|
77
|
+
# records.to_h
|
78
|
+
# end
|
79
|
+
# _cluster_entities.map do |ce|
|
80
|
+
# clusters_hash[ce.cluster_id]
|
81
|
+
# end.compact.sort.join(separator)
|
82
|
+
|
83
|
+
clusters_hash = records.first.is_a?(Array) ? records.to_h : records.index_by(&:itself)
|
84
|
+
_cluster_entities
|
85
|
+
.filter_map { |entity| clusters_hash[entity.cluster_id] }
|
86
|
+
.uniq
|
87
|
+
.sort
|
88
|
+
.join(separator)
|
89
|
+
|
74
90
|
end
|
75
91
|
end
|
76
92
|
|
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.5.5
|
4
|
+
version: 1.5.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gino Barahona
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-06-
|
11
|
+
date: 2025-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|