docbrown/app/services/edge_cache/bust_comment.rb
Alex 7ee8523ba3
Refactor EdgeCache (#11684)
* Refactor EdgeCache

* Update specs

* Add bust comment spec

* Fix more specs

* Use const_get

* Make methods private

* Add .discussion? decorator to Article

* Change variable name to article for clarity
2020-12-02 14:20:22 -05:00

33 lines
895 B
Ruby

module EdgeCache
class BustComment < Bust
def self.call(commentable)
return unless commentable
bust_article_comment(commentable) if commentable.is_a?(Article)
commentable.touch(:last_comment_at) if commentable.respond_to?(:last_comment_at)
bust("#{commentable.path}/comments/")
bust(commentable.path.to_s)
commentable.comments.includes(:user).find_each do |comment|
bust(comment.path)
bust("#{comment.path}?i=i")
end
bust("#{commentable.path}/comments/*")
end
# bust commentable if it's an article
def self.bust_article_comment(article)
bust("/") if Article.published.order(hotness_score: :desc).limit(3).ids.include?(article.id)
return unless article.decorate.discussion?
bust("/")
bust("/?i=i")
bust("?i=i")
end
private_class_method :bust_article_comment
end
end