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

AO3-5578 Use ActiveStorage for existing image uploads #4807

Merged
merged 34 commits into from
Dec 31, 2024

Conversation

brianjaustin
Copy link
Member

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-5578

Purpose

Migrate existing places that use kt-paperclip to ActiveStorage (pseud, collection, and skin icons)

Credit

Brian Austin (they/he)

@brianjaustin brianjaustin added the Has Production Config Changes Modifies the config file and needs special attention when deploying label May 6, 2024
@github-actions github-actions bot added Has Migrations Contains migrations and therefore needs special attention when deploying Gem Updates Awaiting Review labels May 6, 2024
app/models/skin.rb Dismissed Show dismissed Hide dismissed
app/models/skin.rb Dismissed Show dismissed Hide dismissed
@brianjaustin
Copy link
Member Author

Because ActiveStorage doesn't support prefixes within buckets well, we'll need to update the Ansible local config to separate things out IMO that's better anyways, since we currently co-mingle some production and non-production things... 😬 There's probably a way to do this with less friction, but I think this should be OK since we're copying things over

@Bilka2
Copy link
Contributor

Bilka2 commented May 6, 2024

Because ActiveStorage doesn't support prefixes within buckets well, we'll need to update the Ansible local config to separate things out IMO that's better anyways, since we currently co-mingle some production and non-production things...

Looks like #4738 (AO3-6324' comments) agree with you.

app/models/pseud.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

I had a look at all the code except for the rake task.

The fixtures in test/fixtures/pseuds.yml have (empty) lines for icon_file_name, icon_content_type, icon_updated_at and icon_file_size that should probably be removed.

I think there should be a followup Jira issue to remove the icon_file_name, icon_content_type, icon_updated_at and icon_file_size columns from the database for the affected classes.

app/models/collection.rb Outdated Show resolved Hide resolved
app/models/pseud.rb Outdated Show resolved Hide resolved
app/views/challenge_claims/_unposted_claim_blurb.html.erb Outdated Show resolved Hide resolved
features/step_definitions/icon_steps.rb Show resolved Hide resolved
app/helpers/users_helper.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

A few final comments. The rake task looks good, as does the rest of the code.

I also tried a few things in local dev, including looking at various icons in various places, uploading a pseud icon and using that to test the validator and resizing. Resizing acts the same as on production.

app/models/collection.rb Show resolved Hide resolved
app/models/comment.rb Show resolved Hide resolved
app/validators/attachment_validator.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

I think I found how to fix the tests.

app/controllers/collections_controller.rb Outdated Show resolved Hide resolved
spec/requests/muted_users_n_plus_one_spec.rb Show resolved Hide resolved
spec/requests/people_n_plus_one_spec.rb Outdated Show resolved Hide resolved
At this point, I'm a bit at a loss for how to make mutes/blocks not generate n+1.
This should do something, but it ends up doing nothing???
Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

Just some more nitpicks, then this is finally done!

app/controllers/collections_controller.rb Outdated Show resolved Hide resolved
app/controllers/muted/users_controller.rb Outdated Show resolved Hide resolved
app/controllers/blocked/users_controller.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@Bilka2 Bilka2 left a comment

Choose a reason for hiding this comment

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

🎉 🎉 🎉

@Bilka2
Copy link
Contributor

Bilka2 commented Dec 28, 2024

You can remove the imagemagick installation from the automated tests, ActiveStorage replaces it with libvips. (Test run with the removal: https://github.com/Bilka2/otwarchive/actions/runs/12524953209)

@Bilka2
Copy link
Contributor

Bilka2 commented Dec 28, 2024

Also, regarding proxy requests, https://guides.rubyonrails.org/v7.0/active_storage_overview.html#putting-a-cdn-in-front-of-active-storage has a section on making the URL is the CDN host instead of the app host. Is that something we would want to add as well? I would assume no, since cloudflare is in front of the app, not the CDN.

@brianjaustin
Copy link
Member Author

Also, regarding proxy requests, https://guides.rubyonrails.org/v7.0/active_storage_overview.html#putting-a-cdn-in-front-of-active-storage has a section on making the URL is the CDN host instead of the app host. Is that something we would want to add as well? I would assume no, since cloudflare is in front of the app, not the CDN.

I asked @AlbertSPedersen about that, and he said we can have CloudFlare reroute the request to either cache/hit S3 directly as long as it's using an ao3.org URL. So yeah, we don't need to do the extra CDN step in this case

@sarken sarken merged commit e275257 into otwcode:master Dec 31, 2024
29 checks passed
Copy link

sentry-io bot commented Jan 3, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ ActiveRecord::ConnectionNotEstablished: Can't connect to MySQL server on '127.0.0.1' (115) CollectionsController#index View Issue

Did you find this useful? React with a 👍 or 👎

@brianjaustin brianjaustin deleted the AO3-5578-activestorage branch January 28, 2025 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gem Updates Has Migrations Contains migrations and therefore needs special attention when deploying Has Production Config Changes Modifies the config file and needs special attention when deploying Priority: High Reviewed: Ready to Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants