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

Pass optional record in blob finder methods #36727

Merged
merged 1 commit into from
Aug 7, 2019

Conversation

gmcgibbon
Copy link
Member

Summary

Allow record to be optionally passed to blob finders to make sharding easier.

To generically support sharded Active Storage models, we need to specify a model to shard attachments by. The polymorphic record can then be used by a developer in an overridden method:

ActiveSupport.on_load(:active_storage_blob) do
  include ShardedBlob
end

module ShardedBlob
  extend ActiveSupport::Concern
  included do
    def self.find_signed(id, record:)
      find_by!(id: ActiveStorage.verifier.verify(id, purpose: :blob_id), shard_id: record.shard_id)
    end
    # ...
  end
end

This change can be misconstrued as a mistake as the framework doesn't use the record parameter by default, so I've added some tests to make sure it doesn't get removed by mistake.

cc @georgeclaghorn @rafaelfranca

Allow record to be optionally passed to blob finders to make sharding
easier.
@gmcgibbon gmcgibbon merged commit 0f5db10 into rails:master Aug 7, 2019
@gmcgibbon gmcgibbon deleted the active_storage_sharded branch August 7, 2019 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants