Last active
July 19, 2019 12:55
-
-
Save robertomiranda/9977d25b3a1f89e5ec153d0992810e74 to your computer and use it in GitHub Desktop.
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
task :build_top_fans do |_, args| | |
user_id = args[:user_id] | |
redis_client = Redis.new(configurations) | |
top_fan_ids = ( | |
bookmarker_fan_ids(user_id) + | |
commenters_fan_ids(user_id) + | |
cooker_fan_ids(user_id) | |
).uniq | |
# top-fans:user_1: [17, 15, 11, 8, 14, 12, 2, 16, 5, 13] | |
redis_client.set("top-fans:#{user_id}", top_fan_ids.join(",")) | |
end | |
class User | |
def top_fan_ids | |
redis_client.get("top-fans:#{id}".sample(10)).split(",") | |
end | |
def top_fans | |
User.where(id: top_fan_ids) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment