lato_storage 3.1.0 → 3.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a13ab3e65acf06d7619745a47cedc82fe3f6bda167cb2bb51262d91537711068
4
- data.tar.gz: f945005d21633029cfeba26cc13a84faa4d68346cc2f50ff1f41c7f2e018f4dc
3
+ metadata.gz: f3b57af5bf7310b2dff16073667b6b3b9e141fd361bccbcbac863bdcbc80ace7
4
+ data.tar.gz: 4d6cc980af82bf90d66fc8d15cd71d3bb89d03d2da22accd238a2f7835ff9c0e
5
5
  SHA512:
6
- metadata.gz: 63d4288183f841424f5a3cf4ca0362ad0cdff35a3bb503abb0d81896a2b0003b722abd4b2cdfc4484c32d08c4f5b36cab411b392e3edb94dcab6c5335dcb5455
7
- data.tar.gz: e45c65e4e75df74143495f043125ae36fb9b455764494f604b11281debaf20e1a6aa14e6568e7f6f3a325576c918a608e3120dc8521f84035f23cbef81109934
6
+ metadata.gz: d3bab025ec2df8e6604d07cc3215fc58dfa0d458aac1c577d176deb5f831aafb12677da21c4d3c767547072bbd1a84085edc8c1ef2d21c175cf3e48f3ac6df3d
7
+ data.tar.gz: 18970c7c707875c7dd32ccc70878268643c650785bf0ecb38f0cd7d47645eeb13312781a75ccee1fd0eb28bcd03088242249e8d5cdb57b4d268ea5ba32decd8a
@@ -100,6 +100,10 @@ module LatoStorage
100
100
  else
101
101
  ActiveStorage::Blob.count
102
102
  end
103
+ rescue StandardError => e
104
+ Rails.logger.error "Error estimating blobs count: #{e.message}"
105
+ Rails.logger.error e.backtrace.join("\n")
106
+ 0
103
107
  end
104
108
 
105
109
  def attachments_count_loader
@@ -112,6 +116,10 @@ module LatoStorage
112
116
  else
113
117
  ActiveStorage::Attachment.count
114
118
  end
119
+ rescue StandardError => e
120
+ Rails.logger.error "Error estimating attachments count: #{e.message}"
121
+ Rails.logger.error e.backtrace.join("\n")
122
+ 0
115
123
  end
116
124
 
117
125
  def variant_records_count_loader
@@ -126,6 +134,10 @@ module LatoStorage
126
134
  else
127
135
  ActiveStorage::VariantRecord.count
128
136
  end
137
+ rescue StandardError => e
138
+ Rails.logger.error "Error estimating variant records count: #{e.message}"
139
+ Rails.logger.error e.backtrace.join("\n")
140
+ 0
129
141
  end
130
142
 
131
143
  def deletable_blobs_count_loader
@@ -134,15 +146,19 @@ module LatoStorage
134
146
  count += 1
135
147
  end
136
148
  count
149
+ rescue StandardError => e
150
+ Rails.logger.error "Error estimating deletable blobs count: #{e.message}"
151
+ Rails.logger.error e.backtrace.join("\n")
152
+ 0
137
153
  end
138
154
 
139
155
  # Estimate the total storage by multiplying average size of a group sample by total blobs count
140
156
  def total_storage_loader(blobs_count)
141
- sample_size = 1000
157
+ sample_size = 5000
142
158
  total_size = 0
143
159
  sampled_count = 0
144
160
 
145
- ActiveStorage::Blob.order('RANDOM()').limit(sample_size).each do |blob|
161
+ ActiveStorage::Blob.order(id: :desc).limit(sample_size).each do |blob|
146
162
  total_size += blob.byte_size
147
163
  sampled_count += 1
148
164
  end
@@ -151,6 +167,10 @@ module LatoStorage
151
167
 
152
168
  average_size = total_size / sampled_count
153
169
  average_size * blobs_count
170
+ rescue StandardError => e
171
+ Rails.logger.error "Error estimating total storage: #{e.message}"
172
+ Rails.logger.error e.backtrace.join("\n")
173
+ 0
154
174
  end
155
175
 
156
176
  # Estimate content types by sampling blobs
@@ -159,7 +179,7 @@ module LatoStorage
159
179
  sample_size = 5000
160
180
  sampled_count = 0
161
181
 
162
- ActiveStorage::Blob.order('RANDOM()').limit(sample_size).each do |blob|
182
+ ActiveStorage::Blob.order(id: :desc).limit(sample_size).each do |blob|
163
183
  content_type_counts[blob.content_type] += 1
164
184
  sampled_count += 1
165
185
  end
@@ -169,6 +189,10 @@ module LatoStorage
169
189
  # Scale counts to estimated total blobs count
170
190
  content_type_counts.transform_values! { |count| (count.to_f / sampled_count) * blobs_count_loader }
171
191
  content_type_counts.sort_by { |_, count| -count }.first(5)
192
+ rescue StandardError => e
193
+ Rails.logger.error "Error estimating content types: #{e.message}"
194
+ Rails.logger.error e.backtrace.join("\n")
195
+ []
172
196
  end
173
197
  end
174
198
  end
@@ -59,7 +59,7 @@
59
59
  </h5>
60
60
  </div>
61
61
  <div class="card-body">
62
- <% if @data[:content_types].any? %>
62
+ <% if @data[:content_types]&.any? %>
63
63
  <% total = @data[:content_types].sum { |_, count| count } %>
64
64
  <ul class="list-group list-group-flush">
65
65
  <% @data[:content_types].each do |content_type, count| %>
@@ -122,7 +122,7 @@
122
122
  </h5>
123
123
  </div>
124
124
  <div class="card-body">
125
- <% if @data[:largest_blobs].any? %>
125
+ <% if @data[:largest_blobs]&.any? %>
126
126
  <div class="list-group list-group-flush">
127
127
  <% @data[:largest_blobs].each do |blob| %>
128
128
  <a class="list-group-item list-group-item-action" href="<%= blob[:url] %>" target="_blank" rel="noopener noreferrer" download>
@@ -1,3 +1,3 @@
1
1
  module LatoStorage
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante