Skip to content

Instantly share code, notes, and snippets.

@Hamada92
Last active July 22, 2019 22:06
Show Gist options
  • Save Hamada92/b014dc95ef2e26fe52cecb599395d1f2 to your computer and use it in GitHub Desktop.
Save Hamada92/b014dc95ef2e26fe52cecb599395d1f2 to your computer and use it in GitHub Desktop.
how to create new avatar names
# open AvatarUploader and re-define the filename method dynamically- because ewe can't deploy this code,
# it doesn't work for new records as the processing happens async and can't gauarentee that model.id exists, so we
# should run it only after the record is created.
AvatarUploader.class_eval do
def filename
token = OpenSSL::HMAC.hexdigest('SHA256', ENV['AWS_SECRET'], model.id.to_s)
"#{token}.#{file.extension}"
end
end
# backfill
Account.find_each do |account|
account.image.recreate_versions! # a carrierwave method
account.save!
end
# then we can schedule that as a daily task to backfill the new accounts that are created everyday. Can also use a new
# column :obfuscated and set to true when done.
@Hamada92
Copy link
Author

@Alana @erawk :

  1. the script does clean old files. Double checked on staging.
  2. find_each is same as find_in_batches.

Will address other comments on Monday.

@Hamada92
Copy link
Author

Hamada92 commented Jul 22, 2019

@ed

Maybe store the obfuscated file name in the column instead of the boolean and return that if present?

I'd go with this, except that it would cause data redundancy, because the name will be stored in image field as well. A boolean is cleaner in this case I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment