* Rubocop enabled style/alias * Enabled Style/ArrayJoin Cop * Enabled Style/Attr * Enabled Case Equality * Enabled CharacterLiteral * Enabled ColonMethodCall Cop * Enabled CommentAnnotation cop * Enabled PreferredHashMethods Cop * Enabled DoubleNegation Cop * Enabled EachWithObject Cop * Enabled EmptyLiteral Cop * Enabled EvenOdd Cop * Enabled IfWithSemicolon Cop * Enabled Lambda and LambdaCall Cop * Enabled LineEndConcatenation Cop * Enabled ModuleFunction Cop; * Enable NegatedIf and NegatedWhile Cop * Enabled NilComparison Cop * Enabled Not Cop * Enabled NumericLiterals Cop * Enabled OneLineConditional Cop * Enabled PercentLiteralDelimiters Cop * Excluded internal/users_controller from negated_if cop * Reverted the double negation change from github_issue_tag and github_issue.rb" * Enabled PerlBackrefs Cop * Changed Regexp.last_match(1) to Regexp.last_match(0) * Enabled proc cop * Enabled RaiseArgs Cop * Reverted Regexp.last_match(0) to Regexp.last_match(1) * Enabled SelfAssignment Cop * Enabled SingleLineMethods Cop * Enabled SpecialGlobalVars Cop * Enabled VariableInterpolation Cop * Enabled WhenThen Cop * Enabled WhileUntilModifier Cop * Enabled WordArray Cop * Enabled IfUnlessModifier Cop * Enabled GuardClause Cop
62 lines
2.4 KiB
Ruby
62 lines
2.4 KiB
Ruby
class FollowedArticlesController < ApplicationController
|
|
# No authorization required for entirely public controller
|
|
|
|
caches_action :index,
|
|
cache_path: proc { "followed_articles_#{current_user.id}__#{current_user.updated_at}__#{user_signed_in?}" },
|
|
expires_in: 35.minutes
|
|
|
|
def index
|
|
@articles = if current_user
|
|
Rails.cache.fetch(
|
|
"user-#{current_user.id}__#{current_user.updated_at}/followed_articles",
|
|
expires_in: 30.minutes,
|
|
) do
|
|
current_user.followed_articles.
|
|
includes(:user).where("published_at > ?", 5.days.ago).
|
|
order("hotness_score DESC").
|
|
limit(25).map do |a|
|
|
article_json(a) unless inappropriate_hiring_instance(a)
|
|
end.compact
|
|
end
|
|
else
|
|
@articles = []
|
|
end
|
|
classic_article = Suggester::Articles::Classic.new(current_user).get.first
|
|
response.headers["Cache-Control"] = "public, max-age=150"
|
|
render json: {
|
|
articles: @articles,
|
|
classic_article: (article_json(classic_article) if classic_article)
|
|
}.to_json
|
|
end
|
|
|
|
def inappropriate_hiring_instance(article)
|
|
(article.decorate.cached_tag_list_array.include?("hiring") && !article.approved) ||
|
|
(article.decorate.cached_tag_list_array.include?("hiring") && current_user.cached_followed_tag_names.exclude?("hiring"))
|
|
end
|
|
|
|
def article_json(article)
|
|
cache_key = "article_json-#{article.id}-#{article.updated_at}" \
|
|
"-#{article.comments_count}-#{article.reactions_count}"
|
|
Rails.cache.fetch(cache_key, expires_in: 30.minutes) do
|
|
{
|
|
id: article.id,
|
|
path: article.path,
|
|
tag_list: article.decorate.cached_tag_list_array,
|
|
title: article.title,
|
|
published_at_int: article.published_at.to_i,
|
|
published_at_month_day: article.published_at.
|
|
strftime("%B #{article.published_at.day.ordinalize}"),
|
|
is_classic: article.published_at < 7.days.ago,
|
|
comments_count: article.comments_count,
|
|
reactions_count: article.positive_reactions_count,
|
|
language: article.language,
|
|
user: {
|
|
name: article.user.name,
|
|
username: article.user.username,
|
|
profile_image_90: ProfileImage.new(article.user).get(90)
|
|
},
|
|
flare_tag: FlareTag.new(article).tag_hash
|
|
}
|
|
end
|
|
end
|
|
end
|