-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Precache actual files instead of storing lengths (#644)
Co-authored-by: Charlotte Van Petegem <[email protected]>
- Loading branch information
Showing
32 changed files
with
310 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CreateTranscodedItemJob < ApplicationJob | ||
queue_as :within_30_seconds | ||
|
||
def perform(audio_file, codec_conversion) | ||
# Check that this transcoded_item was not created while this job was in the queue | ||
return if TranscodedItem.find_by(audio_file:, codec_conversion:).present? | ||
|
||
uuid = TranscodedItem.uuid_for(codec_conversion) | ||
path = TranscodedItem.path_for(codec_conversion, uuid) | ||
FileUtils.mkdir_p Pathname.new(path).parent | ||
audio_file.convert(codec_conversion, path) | ||
|
||
TranscodedItem.transaction do | ||
# Check that the transcoded item was not created while we were executing | ||
if TranscodedItem.find_by(audio_file:, codec_conversion:).present? | ||
FileUtils.rm_f path | ||
else | ||
TranscodedItem.create!(audio_file:, codec_conversion:, uuid:) | ||
end | ||
end | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
app/jobs/queue_transcoded_items_for_codec_conversion_job.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class QueueTranscodedItemsForCodecConversionJob < ApplicationJob | ||
queue_as :within_30_seconds | ||
|
||
def perform(codec_conversion) | ||
AudioFile.find_in_batches do |batch| | ||
jobs = batch.filter_map do |af| | ||
CreateTranscodedItemJob.new(af, codec_conversion) if Rails.configuration.queue_create_transcoded_item_if.call(af) | ||
end | ||
ActiveJob.perform_all_later(jobs) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.