Last active
October 18, 2018 05:13
-
-
Save CaDs/62e4807e4895b1b4d9f9ded3721508e1 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
class Post < ApplicationRecord | |
belongs_to :user | |
after_create_commit :enqueue_delivery | |
class << self | |
def cache_key_for(id:) | |
"cached_post/#{id}" | |
end | |
def id_from_cache_key(key:) | |
key.split('/').last | |
end | |
end | |
def enqueue_delivery | |
PostDeliveryJob.perform_async(post_id: id) | |
end | |
def deliver_to_followers | |
recipients = user.followers + [user] | |
recipients.each do |follower| | |
follower.add_to_cache(post: self) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment