lato_storage 3.0.4 → 3.0.5

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: a8fee0fc85564d404c276d8b7d5ea615f175e4774c54c1b18820774057380c0a
4
- data.tar.gz: d50ea647467fb4fe863fb175861d29095cd2e591aa98c2ed0ebd95fe6acc98f0
3
+ metadata.gz: 6e3025eada87329a0eb5a53da4eabcb1e3876c09c5730fdcec324904ec420604
4
+ data.tar.gz: d17b7f2355f1118aa280b0c59df2a323666313f5db0b755e3ad137c5d18998b8
5
5
  SHA512:
6
- metadata.gz: 6e5e4526f7d2624bd1c0fb7283e62e72f745271d7fa9d0a6ed02ff559c65ce528242e496d9c9746eb41713456f442b79fda7ac6a418f6ee28c834aa6ffcf67f4
7
- data.tar.gz: 564e3c68d42a758c70c44c22cbb4c7fc6d4a21b65b08cc62515fea3a05fc0a2a86e96f988d9efec0904f6b026254ac150ed3f3c574c6ba4a47bb026050150231
6
+ metadata.gz: 9a6ad7617bcda1e29b62374f1e5c947a16a0c06b67f0b692ba41c45968773d354b307dbae0a387349a7988a5ed0db8425ba567815ff482c5f1e4b209a04dbdb6
7
+ data.tar.gz: cdd52bbe6f56d9990cb2edd821500c248addaa841ce72353081e70528953a5ba752423425a2cf48489a66b5f786e4b273183883fc0d1f9247433b9f31e139355
@@ -6,9 +6,9 @@ module LatoStorage
6
6
  before_action { active_sidebar(:lato_storage); active_navbar(:lato_storage) }
7
7
 
8
8
  def index
9
- @blobs_count = ActiveStorage::Blob.count
10
- @attachments_count = ActiveStorage::Attachment.count
11
- @variant_records_count = defined?(ActiveStorage::VariantRecord) ? ActiveStorage::VariantRecord.count : 0
9
+ @blobs_count = blobs_count
10
+ @attachments_count = attachments_count
11
+ @variant_records_count = variant_records_count
12
12
  @deletable_blobs_count = ActiveStorage::Blob.unattached.where('active_storage_blobs.created_at < ?', 12.hours.ago).count
13
13
 
14
14
  @total_storage = ActiveStorage::Blob.sum(:byte_size)
@@ -40,5 +40,39 @@ module LatoStorage
40
40
 
41
41
  redirect_to lato.root_path, alert: 'You have not access to this section.'
42
42
  end
43
+
44
+ private
45
+
46
+ def blobs_count
47
+ return ActiveStorage::Blob.count unless LatoStorage.config.optimize_performances
48
+
49
+ if ActiveRecord::Base.connection.adapter_name.downcase == "postgresql"
50
+ ActiveRecord::Base.connection.execute("SELECT reltuples::bigint AS estimate FROM pg_class WHERE relname = 'active_storage_blobs';").first["estimate"]
51
+ else
52
+ ActiveStorage::Blob.count
53
+ end
54
+ end
55
+
56
+ def attachments_count
57
+ return ActiveStorage::Attachment.count unless LatoStorage.config.optimize_performances
58
+
59
+ if ActiveRecord::Base.connection.adapter_name.downcase == "postgresql"
60
+ ActiveRecord::Base.connection.execute("SELECT reltuples::bigint AS estimate FROM pg_class WHERE relname = 'active_storage_attachments';").first["estimate"]
61
+ else
62
+ ActiveStorage::Attachment.count
63
+ end
64
+ end
65
+
66
+ def variant_records_count
67
+ return 0 unless defined?(ActiveStorage::VariantRecord)
68
+ return ActiveStorage::VariantRecord.count unless LatoStorage.config.optimize_performances
69
+
70
+ if defined?(ActiveStorage::VariantRecord) && ActiveRecord::Base.connection.adapter_name.downcase == "postgresql"
71
+ ActiveRecord::Base.connection.execute("SELECT reltuples::bigint AS estimate FROM pg_class WHERE relname = 'active_storage_variant_records';").first["estimate"]
72
+ else
73
+ ActiveStorage::VariantRecord.count
74
+ end
75
+ end
76
+
43
77
  end
44
78
  end
@@ -4,6 +4,6 @@
4
4
 
5
5
  <div class="card">
6
6
  <div class="card-body">
7
- <%= lato_index @attachments %>
7
+ <%= lato_index @attachments, skip_total_count: LatoStorage.config.optimize_performances %>
8
8
  </div>
9
9
  </div>
@@ -4,6 +4,6 @@
4
4
 
5
5
  <div class="card">
6
6
  <div class="card-body">
7
- <%= lato_index @blobs %>
7
+ <%= lato_index @blobs, skip_total_count: LatoStorage.config.optimize_performances %>
8
8
  </div>
9
9
  </div>
@@ -4,6 +4,6 @@
4
4
 
5
5
  <div class="card">
6
6
  <div class="card-body">
7
- <%= lato_index @variant_records %>
7
+ <%= lato_index @variant_records, skip_total_count: LatoStorage.config.optimize_performances %>
8
8
  </div>
9
9
  </div>
@@ -3,8 +3,16 @@ module LatoStorage
3
3
  # This class contains the default configuration of the engine.
4
4
  ##
5
5
  class Config
6
-
6
+
7
+ # This option allows to optimize performances by skipping count queries.
8
+ # If set to true, it will not perform count queries for collections and use other methods instead.
9
+ # This can significantly speed up operations but may lead to inaccuracies in counts.
10
+ # This is really useful for large datasets where performance is critical.
11
+ # Default is false.
12
+ attr_accessor :optimize_performances
13
+
7
14
  def initialize
15
+ @optimize_performances = false
8
16
  end
9
17
  end
10
18
  end
@@ -1,3 +1,3 @@
1
1
  module LatoStorage
2
- VERSION = "3.0.4"
2
+ VERSION = "3.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-19 00:00:00.000000000 Z
11
+ date: 2025-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails