-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regard :from_version option on calling #recreate_versions! with args #1879
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,23 +213,49 @@ def url(*args) | |
# Recreate versions and reprocess them. This can be used to recreate | ||
# versions if their parameters somehow have changed. | ||
# | ||
def recreate_versions!(*versions) | ||
def recreate_versions!(*names) | ||
# Some files could possibly not be stored on the local disk. This | ||
# doesn't play nicely with processing. Make sure that we're only | ||
# processing a cached file | ||
# | ||
# The call to store! will trigger the necessary callbacks to both | ||
# process this version and all sub-versions | ||
if versions.any? | ||
file = sanitized_file if !cached? | ||
store_versions!(file, versions) | ||
|
||
if names.any? | ||
file = sanitized_file | ||
# We should somehow filter versions to cache in #cache_versions!. | ||
# Passing arguments through all of those callbacks is difficult, so @versions_to_cache | ||
# instance variable is introduced. It's used only here and in #cache_versions!. | ||
@versions_to_cache = substitute_dependent_with_parents(names) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would avoid code like this at the current moment. I would find a way to extract this or improve the current method. I know that there might be others places where we are instantiating variables outside of the constructor of the class, but as of now, I see this as a bad smell and should be avoided at all costs. |
||
versions_to_store = (@versions_to_cache + names).uniq | ||
cache!(file) | ||
@versions_to_cache = nil | ||
store_versions!(file, versions_to_store) | ||
else | ||
cache! if !cached? | ||
store! | ||
end | ||
end | ||
|
||
private | ||
|
||
# To correctly cache dependent version we need to be sure that its parent is cached, too. | ||
# But caching parent version automatically cache its descendents. | ||
# So, while recreating certain versions in #cache_versions! we should skip dependent versions | ||
# as soon as their caching will be automatically started by parent. | ||
def substitute_dependent_with_parents(names) | ||
with_dependencies = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can convert this to a inject |
||
versions.each do |name, uploader| | ||
next unless names.include?(name) | ||
if uploader.class.version_options[:from_version] | ||
with_dependencies << uploader.class.version_options[:from_version] | ||
else | ||
with_dependencies << name | ||
end | ||
end | ||
with_dependencies.uniq | ||
end | ||
|
||
def assign_parent_cache_id(file) | ||
active_versions.each do |name, uploader| | ||
uploader.parent_cache_id = @cache_id | ||
|
@@ -264,6 +290,7 @@ def full_original_filename | |
|
||
def cache_versions!(new_file) | ||
dependent_versions.each do |name, v| | ||
next if @versions_to_cache && !@versions_to_cache.include?(name) | ||
v.send(:cache_id=, @cache_id) | ||
v.cache!(new_file) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to the wiki, the Readme is already too big for a very specific user case