This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Preloads ActiveRecord model associations with shared object references. | |
# This internally uses ActiveRecord::Associations::Preloader but works around some of its limitations. | |
# It works around a bug with associations containing loaded/unloaded models. https://github.com/rails/rails/issues/32140 | |
# | |
# Usage: | |
# Preloader.new(models, association_spec).preload | |
# Also supports a third `scope` argument that is used when querying. | |
# | |
# There is an additional class utility method `uniquify_associations` to share object references that can be useful in preloading. | |
class Preloader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bcrypt' | |
passwords = ['password 1', 'password 2', 'password 3'] | |
password_hashes = ParallelWorkforce.perform_all( | |
actor_classes: Array.new(passwords.size) { PasswordHashGenerator }, | |
actor_args_array: passwords.map { |password| { password: password } }, | |
) | |
# check that password hashes match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bcrypt' | |
class PasswordHashGenerator | |
attr_reader :password | |
def initialize(password:) | |
@password = password | |
end | |
def perform |