File tree Expand file tree Collapse file tree 5 files changed +32
-2
lines changed
app/models/active_storage/blob Expand file tree Collapse file tree 5 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 1+ * Only enqueue analysis jobs for blobs with non-null analyzer classes.
2+
3+ * Gannon McGibbon*
4+
15* Previews are created on the same service as the original blob.
26
37 * Peter Zhu*
Original file line number Diff line number Diff line change @@ -29,12 +29,16 @@ def analyze
2929 update! metadata : metadata . merge ( extract_metadata_via_analyzer )
3030 end
3131
32- # Enqueues an ActiveStorage::AnalyzeJob which calls #analyze.
32+ # Enqueues an ActiveStorage::AnalyzeJob which calls #analyze, or calls #analyze inline based on analyzer class configuration .
3333 #
3434 # This method is automatically called for a blob when it's attached for the first time. You can call it to analyze a blob
3535 # again (e.g. if you add a new analyzer or modify an existing one).
3636 def analyze_later
37- ActiveStorage ::AnalyzeJob . perform_later ( self )
37+ if analyzer_class . analyze_later?
38+ ActiveStorage ::AnalyzeJob . perform_later ( self )
39+ else
40+ analyze
41+ end
3842 end
3943
4044 # Returns true if the blob has been analyzed.
Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ def self.accept?(blob)
1212 false
1313 end
1414
15+ # Implement this method in concrete subclasses. It will determine if blob anlysis
16+ # should be done in a job or performed inine. By default, analysis is enqueued in a job.
17+ def self . analyze_later?
18+ true
19+ end
20+
1521 def initialize ( blob )
1622 @blob = blob
1723 end
Original file line number Diff line number Diff line change @@ -6,6 +6,10 @@ def self.accept?(blob)
66 true
77 end
88
9+ def self . analyze_later?
10+ false
11+ end
12+
913 def metadata
1014 { }
1115 end
Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ class ActiveStorage::AttachmentTest < ActiveSupport::TestCase
2525 assert_equal 2736 , blob . metadata [ :height ]
2626 end
2727
28+ test "attaching a un-analyzable blob" do
29+ blob = create_blob ( filename : "blank.txt" )
30+
31+ assert_not_predicate blob , :analyzed?
32+
33+ assert_no_enqueued_jobs do
34+ @user . highlights . attach ( blob )
35+ end
36+
37+ assert_predicate blob . reload , :analyzed?
38+ end
39+
2840 test "mirroring a directly-uploaded blob after attaching it" do
2941 with_service ( "mirror" ) do
3042 blob = directly_upload_file_blob
You can’t perform that action at this time.
0 commit comments