* Fix archived readinglist reactions affecting count The reading list count badge on the home page currently takes all readinglist reactions into account, but we shouldn't be including those that are marked "archived." Secondarily this fixes a bug that affects only admin users: all reactions created by admins were given the status "confirmed" instead of the expected "valid" status.
33 lines
705 B
Ruby
33 lines
705 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).where.not(status: "archived").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
|