* Rename positive_reactions_count to public_reactions_count * Add positive reactions count back in so we can remove it * Use public_category method for reactions * Add positive_reactions_count in case any old caches rely on it * Add positive_rxn_count to account for API endpoints * Remove unused method * One more spot... * Add method back in because of caches * Update specs to match new functionality * Fix typo * Remove unused methods
33 lines
671 B
Ruby
33 lines
671 B
Ruby
class ReadingList
|
|
attr_accessor :user
|
|
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
def get
|
|
Article.
|
|
joins(:reactions).
|
|
includes(:user).
|
|
where(reactions: reaction_criteria).
|
|
order("reactions.created_at DESC")
|
|
end
|
|
|
|
def cached_ids_of_articles
|
|
Rails.cache.fetch("reading_list_ids_of_articles_#{user.id}_#{user.public_reactions_count}") do
|
|
ids_of_articles
|
|
end
|
|
end
|
|
|
|
def ids_of_articles
|
|
Reaction.where(reaction_criteria).order("created_at DESC").pluck(:reactable_id)
|
|
end
|
|
|
|
def count
|
|
get.size
|
|
end
|
|
|
|
def reaction_criteria
|
|
{ user_id: user.id, reactable_type: "Article", category: "readinglist" }
|
|
end
|
|
end
|