docbrown/app/labor/reading_list.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

32 lines
658 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.updated_at}") 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