Skip to content
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

WIP: Use Active Storage instead of Dragonfly #2288

Closed
wants to merge 22 commits into from

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Apr 10, 2022

What is this pull request for?

Use ActiveStorage instead of Dragonfly for picture and file attachments.

Important changes

  • Animated gifs do not work (always flattened to single image) (TODO: Only a vips issue?)
  • Upfront processing of image variants after upload is not supported in Rails 6 (Need Rails 7 to re-implement support)
  • Passing additional params to the picture url is not supported anymore

TODO

  • Use ActiveStorage for Alchemy::Attachment as well
  • Figure out how to persist meta data. Active Storage uses a background job to analyze and offers no callbacks
  • Add custom pictures controller to handle authentication and use proxy instead of redirect
  • Remove Dragonfly dependency and related code
  • Remove our custom picture variants and accompany files
  • Write upgrade task to create ActiveStorage variants from our variants
  • Drop old tables?

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@tvdeyen tvdeyen force-pushed the active-storage branch 3 times, most recently from 8c7c2c8 to b457134 Compare April 11, 2022 15:33
@tvdeyen tvdeyen added this to the 6.1 milestone Apr 11, 2022
}
end

def sharpen_option(options)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method sharpen_option has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

Helpful for local debugging in the browser
Necessary for active storage image transforms
scope :by_file_type, ->(file_type) { where(file_mime_type: file_type) }
scope :by_file_type, ->(file_type) {
with_attached_file.joins(:file_blob).where(active_storage_blobs: { content_type: file_type })
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/BlockAlignment: } at 38, 6 is not aligned with ->(file_type) { at 36, 25 or scope :by_file_type, ->(file_type) { at 36, 4.

scope :by_file_format, ->(format) { where(image_file_format: format) }
scope :by_file_format, ->(file_format) {
with_attached_image_file.joins(:image_file_blob).where(active_storage_blobs: { content_type: file_format })
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/BlockAlignment: } at 96, 6 is not aligned with ->(file_format) { at 94, 27 or scope :by_file_format, ->(file_format) { at 94, 4.

end

after(:build) do |picture, acc|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

end
end

after(:build) do |picture, acc|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

ActiveStorage uses the image_processing gem to process images. This uses a hash to describe the conversion instead of a string
Instead of using the Dragonfly Model validations we write our own. That way we can use another image attachment library more easily
The vips image_processing processor sharpens images by default. This disables this behavior.
Active storage already knows if a file is convertible
This avoids N+1 in the image library
Using activestorage methods to read the values. Ideally we would cache these values, but active storage asynchronously sets these values.
We do not want to redirect to the service url, but use the proxy instead. This only works with Rails >= 6.1
Now that we use ActiveStorage we can remove our custom picture variant handling
This method is the only one left after the PictureVariant and PictureThumb removal.
Active storage has the mime type stored not the extension.
@pascalbetz
Copy link
Contributor

@tvdeyen let me know if i can help on this one. I've inherited some hacky ActiveStorage extensions that could be replaced by this :-)

@tvdeyen
Copy link
Member Author

tvdeyen commented May 19, 2022

@pascalbetz thanks. feel free to review this PR and comment on the todos above. Currently I think ActiveStorage is not a perfect drop in replacement for Dragonfly.

There are some blocking issues, especially the off band meta data update combined with the lack of callbacks.

@tvdeyen
Copy link
Member Author

tvdeyen commented May 19, 2022

I am currently not working on this actively. Feel free to open PRs against my branch if you see something you can help with. There is no hurry with that, as well.

@pascalbetz
Copy link
Contributor

I think we rather move our code over to dragonfly then, if AS will not replace Dragonfly anytime soon.
Our implementation is super hacky and absolutely incomplete and lacking tons of things that Alchemy provides with Dragonfly out of the box.
So if you say that this work is currently on hold because of shortcomings of AS, then this will probably not become a prio on your side in short term?

@tvdeyen
Copy link
Member Author

tvdeyen commented May 28, 2022

I think we rather move our code over to dragonfly then, if AS will not replace Dragonfly anytime soon.
Our implementation is super hacky and absolutely incomplete and lacking tons of things that Alchemy provides with Dragonfly out of the box.
So if you say that this work is currently on hold because of shortcomings of AS, then this will probably not become a prio on your side in short term?

No, this does not have a high priority and will not happen in short term. Dragonfly is a good choice for file attachments in Rails and it does not have the shortcomings ActiveStorage has.

@pascalbetz
Copy link
Contributor

okay, thanks for the update.

@github-actions
Copy link

This pull request has not seen any activiy in a long time.
Probably because of missing tests or a necessary rebase.
This PR will be closed in 7 days if no further activity happens.

@github-actions github-actions bot added the Stale label Jul 28, 2022
@github-actions
Copy link

github-actions bot commented Aug 5, 2022

This pull request has not seen any activiy in a long time.
Probably because of missing tests or a necessary rebase.
Please open a new PR to latest main if you want to continue working on this.
Thanks for the contribution.

@github-actions github-actions bot closed this Aug 5, 2022
@tvdeyen tvdeyen reopened this Mar 13, 2023
@tvdeyen tvdeyen self-assigned this Mar 13, 2023
@tvdeyen tvdeyen modified the milestones: 6.1, 7.0 Mar 13, 2023
@github-actions github-actions bot removed the Stale label Mar 14, 2023
@tvdeyen tvdeyen removed this from the 7.0 milestone Mar 30, 2023
@github-actions
Copy link

This pull request has not seen any activiy in a long time.
Probably because of missing tests or a necessary rebase.
This PR will be closed in 7 days if no further activity happens.

@github-actions github-actions bot added the Stale label May 30, 2023
@github-actions
Copy link

This pull request has not seen any activiy in a long time.
Probably because of missing tests or a necessary rebase.
Please open a new PR to latest main if you want to continue working on this.
Thanks for the contribution.

@github-actions github-actions bot closed this Jun 29, 2023
@tvdeyen
Copy link
Member Author

tvdeyen commented Aug 2, 2023

Re-opened #2544 to continue the work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants