stratocaster 0.4.0 → 0.4.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/lib/stratocaster/attacher.rb +6 -4
- data/lib/stratocaster/purge_job.rb +6 -2
- data/lib/stratocaster/version.rb +1 -1
- data/lib/stratocaster.rb +11 -0
- 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: 2b7b8160480bffa7931410db64dea27330921142958f7837122f18bc5f7eac9f
|
|
4
|
+
data.tar.gz: 7697cb85701d1b6aec1e2a1203b6215b6ba2a56f25203fb87575411b35d66590
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5718f1372392ffe3a78c312fe74ba33714bbe5573b15831d7a544646ee9f88f04dc6729223108dbd1775901009b5d81e70efb6ad437aa8dd4d313e06773056d3
|
|
7
|
+
data.tar.gz: 35e75720fe35d562706f317f169c894ad559be2ada5af218f2c93a5a382197bcec987ce62bc2024ecbb260f76f52e6324d263c3d93c8e5f8b8fbca60f895a813
|
|
@@ -8,6 +8,7 @@ module Stratocaster
|
|
|
8
8
|
|
|
9
9
|
define_method("#{base_name}?") { send("#{base_name}_filename").present? }
|
|
10
10
|
strattachments.merge!(base_name => [])
|
|
11
|
+
Stratocaster.attachments << [name, "#{base_name}_filename"] if name
|
|
11
12
|
block.call(base_name)
|
|
12
13
|
before_save :upload_strattachment_originals
|
|
13
14
|
after_commit :perform_processing_job, on: %i[create update]
|
|
@@ -67,14 +68,15 @@ module Stratocaster
|
|
|
67
68
|
# it. Collect the keys and let a job do the deleting once the transaction has committed, so a rollback
|
|
68
69
|
# also stops us from orphaning rows that still point at deleted files.
|
|
69
70
|
def purge_strattachments
|
|
70
|
-
|
|
71
|
+
files = Hash.new { |hash, filename| hash[filename] = [] }
|
|
72
|
+
strattachments.each do |base_name, variants|
|
|
71
73
|
filename = send("#{base_name}_filename")
|
|
72
|
-
next
|
|
74
|
+
next if filename.blank?
|
|
73
75
|
|
|
74
|
-
[filename]
|
|
76
|
+
files[filename].concat(variants.map { |variant_name, _options| strat_md5(filename, variant_name) })
|
|
75
77
|
end
|
|
76
78
|
|
|
77
|
-
Stratocaster::PurgeJob.perform_later(
|
|
79
|
+
Stratocaster::PurgeJob.perform_later(files.to_h) if files.any?
|
|
78
80
|
end
|
|
79
81
|
end
|
|
80
82
|
end
|
|
@@ -4,8 +4,12 @@ module Stratocaster
|
|
|
4
4
|
|
|
5
5
|
self.priority = 3
|
|
6
6
|
|
|
7
|
-
def perform(
|
|
8
|
-
|
|
7
|
+
def perform(files)
|
|
8
|
+
files.each do |original, variants|
|
|
9
|
+
next if Stratocaster.referenced?(original)
|
|
10
|
+
|
|
11
|
+
[original, *variants].each { |filename| purge(filename) }
|
|
12
|
+
end
|
|
9
13
|
end
|
|
10
14
|
|
|
11
15
|
private
|
data/lib/stratocaster/version.rb
CHANGED
data/lib/stratocaster.rb
CHANGED
|
@@ -12,4 +12,15 @@ require "image_processing/vips"
|
|
|
12
12
|
|
|
13
13
|
module Stratocaster
|
|
14
14
|
cattr_accessor :config
|
|
15
|
+
mattr_accessor :attachments, default: Set.new
|
|
16
|
+
|
|
17
|
+
# Filenames are content hashes, so two records holding the same image share every stored file. A file is only
|
|
18
|
+
# safe to delete once no attachment column anywhere still points at it.
|
|
19
|
+
def self.referenced?(filename)
|
|
20
|
+
Rails.application.eager_load! unless Rails.application.config.eager_load
|
|
21
|
+
|
|
22
|
+
attachments.any? do |class_name, column|
|
|
23
|
+
class_name.safe_constantize&.unscoped&.exists?(column => filename)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
15
26
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stratocaster
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Johan Halse
|
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
69
|
version: '0'
|
|
70
70
|
requirements: []
|
|
71
|
-
rubygems_version: 4.0.
|
|
71
|
+
rubygems_version: 4.0.20
|
|
72
72
|
specification_version: 4
|
|
73
73
|
summary: Another flippin image uploader
|
|
74
74
|
test_files: []
|