diff --git a/.erb-lint.yml b/.erb-lint.yml index 1690c110b8467..927b224d1c8fc 100644 --- a/.erb-lint.yml +++ b/.erb-lint.yml @@ -19,6 +19,8 @@ linters: rubocop_config: inherit_from: - .rubocop.yml + Layout/InitialIndentation: + Enabled: false Layout/TrailingBlankLines: Enabled: false Lint/UselessAssignment: diff --git a/app/controllers/api/v0/articles_controller.rb b/app/controllers/api/v0/articles_controller.rb index f3737bcb9cac1..234bee5d9155b 100644 --- a/app/controllers/api/v0/articles_controller.rb +++ b/app/controllers/api/v0/articles_controller.rb @@ -26,7 +26,7 @@ def index end def show - relation = Article.includes(:user).where(published: true) + relation = Article.published.includes(:user) @article = if params[:id] == "by_path" relation.find_by!(path: params[:url]).decorate else diff --git a/app/controllers/api/v0/videos_controller.rb b/app/controllers/api/v0/videos_controller.rb index 7d4aaad47dd41..5ffb67041c03d 100644 --- a/app/controllers/api/v0/videos_controller.rb +++ b/app/controllers/api/v0/videos_controller.rb @@ -11,9 +11,9 @@ class VideosController < ApiController def index @page = params[:page] - @video_articles = Article.where.not(video: [nil, ""], video_thumbnail_url: [nil, ""]). + @video_articles = Article.published. + where.not(video: [nil, ""], video_thumbnail_url: [nil, ""]). where("score > ?", -4). - where(published: true). order("hotness_score DESC"). page(params[:page].to_i).per(24) end diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 836e16b6e9a1b..6d4abba0d6c8b 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -9,7 +9,7 @@ class ArticlesController < ApplicationController def feed skip_authorization - @articles = Article.where(published: true). + @articles = Article.published. select(:published_at, :processed_html, :user_id, :organization_id, :title, :path). order(published_at: :desc). page(params[:page].to_i).per(12) diff --git a/app/controllers/internal/articles_controller.rb b/app/controllers/internal/articles_controller.rb index 962d77911cfea..07986092791f0 100644 --- a/app/controllers/internal/articles_controller.rb +++ b/app/controllers/internal/articles_controller.rb @@ -3,70 +3,57 @@ class Internal::ArticlesController < Internal::ApplicationController def index @pending_buffer_updates = BufferUpdate.where(status: "pending").includes(:article) - case params[:state] + case params[:state] when /not\-buffered/ days_ago = params[:state].split("-")[2].to_f - @articles = Article. - where(last_buffered: nil, published: true). - includes(:user). - includes(:buffer_updates). - order("positive_reactions_count DESC"). - page(params[:page]). + @articles = Article.published.where(last_buffered: nil). where("published_at > ? OR crossposted_at > ?", days_ago.days.ago, days_ago.days.ago). + includes(:user, :buffer_updates). limited_columns_internal_select. + order("positive_reactions_count DESC"). + page(params[:page]). per(50) when /top\-/ - @articles = Article. - where(published: true). + @articles = Article.published. where("published_at > ?", params[:state].split("-")[1].to_i.months.ago). - includes(:user). - includes(:buffer_updates). + includes(:user, :buffer_updates). + limited_columns_internal_select. order("positive_reactions_count DESC"). page(params[:page]). - limited_columns_internal_select. per(50) when "satellite" - @articles = Article. - where(last_buffered: nil, published: true). - includes(:user). - includes(:buffer_updates). - order("hotness_score DESC"). + @articles = Article.published.where(last_buffered: nil). + includes(:user, :buffer_updates). tagged_with(Tag.bufferized_tags, any: true). - page(params[:page]). limited_columns_internal_select. + order("hotness_score DESC"). + page(params[:page]). per(60) when "boosted-additional-articles" - @articles = Article. - includes(:user). + @articles = Article.boosted_via_additional_articles. + includes(:user, :buffer_updates). + limited_columns_internal_select. order("published_at DESC"). - includes(:buffer_updates). - boosted_via_additional_articles. page(params[:page]). - per(100). - limited_columns_internal_select + per(100) when "chronological" - @articles = Article. - where(published: true). + @articles = Article.published. + limited_columns_internal_select. order("published_at DESC"). page(params[:page]). - limited_columns_internal_select. per(50) else # MIX - @articles = Article. - where(published: true). + @articles = Article.published. + limited_columns_internal_select. order("hotness_score DESC"). page(params[:page]). - limited_columns_internal_select. per(30) - @featured_articles = Article. - where(published: true). - or(Article.where(published_from_feed: true)). + @featured_articles = Article.published.or(Article.where(published_from_feed: true)). where(featured: true). where("featured_number > ?", Time.current.to_i). - includes(:user). - includes(:buffer_updates). + includes(:user, :buffer_updates). limited_columns_internal_select. order("featured_number DESC") end diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index 6f900283d1c1d..bab82a395c2cb 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -5,15 +5,14 @@ def index skip_authorization return unless current_user&.trusted - @articles = Article.where(published: true). + @articles = Article.published. includes(:rating_votes). where("rating_votes_count < 3"). where("score > -5"). order("hotness_score DESC").limit(100) - if params[:tag].present? - @articles = @articles. - cached_tagged_with(params[:tag]) - end + + @articles = @articles.cached_tagged_with(params[:tag]) if params[:tag].present? + @articles = @articles.decorate end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 51798a2f90f55..2256fe702ca18 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -61,12 +61,12 @@ def live end def shecoded - @top_articles = Article.tagged_with(%w[shecoded shecodedally theycoded], any: true). - where(published: true, approved: true).where("published_at > ? AND score > ?", 3.weeks.ago, 28). + @top_articles = Article.published.tagged_with(%w[shecoded shecodedally theycoded], any: true). + where(approved: true).where("published_at > ? AND score > ?", 3.weeks.ago, 28). order(Arel.sql("RANDOM()")). includes(:user).decorate - @articles = Article.tagged_with(%w[shecoded shecodedally theycoded], any: true). - where(published: true, approved: true).where("published_at > ? AND score > ?", 3.weeks.ago, -8). + @articles = Article.published.tagged_with(%w[shecoded shecodedally theycoded], any: true). + where(approved: true).where("published_at > ? AND score > ?", 3.weeks.ago, -8). order(Arel.sql("RANDOM()")). where.not(id: @top_articles.pluck(:id)). includes(:user).decorate @@ -77,8 +77,7 @@ def shecoded private # helpers def latest_published_welcome_thread - Article.where(user_id: ApplicationConfig["DEVTO_USER_ID"], published: true). - tagged_with("welcome").last + Article.published.where(user_id: ApplicationConfig["DEVTO_USER_ID"]).tagged_with("welcome").last end def members_for_display diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 5098a9f8adb72..125ae8d48ea7e 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -141,8 +141,7 @@ def handle_podcast_index def handle_organization_index @user = @organization - @stories = ArticleDecorator.decorate_collection(@organization.articles. - where(published: true). + @stories = ArticleDecorator.decorate_collection(@organization.articles.published. limited_column_select. includes(:user). order("published_at DESC").page(@page).per(8)) @@ -159,8 +158,7 @@ def handle_user_index return end assign_user_comments - @stories = ArticleDecorator.decorate_collection(@user. - articles.where(published: true). + @stories = ArticleDecorator.decorate_collection(@user.articles.published. limited_column_select. order("published_at DESC").page(@page).per(user_signed_in? ? 2 : 5)) @article_index = true @@ -257,11 +255,7 @@ def assign_podcasts def article_finder(num_articles) tag = params[:tag] - articles = Article.where(published: true). - includes(:user). - limited_column_select. - page(@page). - per(num_articles) + articles = Article.published.includes(:user).limited_column_select.page(@page).per(num_articles) articles = articles.cached_tagged_with(tag) if tag.present? # More efficient than tagged_with articles end diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb index d000dbf9085ad..7dd8cd696e157 100644 --- a/app/controllers/videos_controller.rb +++ b/app/controllers/videos_controller.rb @@ -7,9 +7,9 @@ def new end def index - @video_articles = Article.where.not(video: [nil, ""], video_thumbnail_url: [nil, ""]). + @video_articles = Article.published. + where.not(video: [nil, ""], video_thumbnail_url: [nil, ""]). where("score > ?", -4). - where(published: true). order("hotness_score DESC"). page(params[:page].to_i).per(24) set_surrogate_key_header "videos_landing_page" diff --git a/app/facades/dashboard/pro.rb b/app/facades/dashboard/pro.rb index 2d693ffe8911e..ed17fa825875c 100644 --- a/app/facades/dashboard/pro.rb +++ b/app/facades/dashboard/pro.rb @@ -8,7 +8,8 @@ def initialize(user_or_org) def user_or_org_article_ids @user_or_org_article_ids ||= - Article.where("#{user_or_org.class.name.downcase}_id" => user_or_org.id, published: true).pluck(:id) + Article.published.where("#{user_or_org.class.name.downcase}_id" => user_or_org.id). + pluck(:id) end def this_week_reactions diff --git a/app/labor/article_suggester.rb b/app/labor/article_suggester.rb index 06884703632a9..949850b90bedf 100644 --- a/app/labor/article_suggester.rb +++ b/app/labor/article_suggester.rb @@ -13,7 +13,7 @@ def articles(num = 4) end def other_suggestions(num = 4) - Article.where(featured: true, published: true). + Article.published.where(featured: true). where.not(id: article.id). order("hotness_score DESC"). includes(:user). @@ -22,8 +22,7 @@ def other_suggestions(num = 4) end def suggestions_by_tag - Article.tagged_with(article.tag_list, any: true). - where(published: true). + Article.published.tagged_with(article.tag_list, any: true). where.not(id: article.id). order("hotness_score DESC"). includes(:user). diff --git a/app/labor/badge_rewarder.rb b/app/labor/badge_rewarder.rb index 08aefd58081ac..a5f3ba5a0cc33 100644 --- a/app/labor/badge_rewarder.rb +++ b/app/labor/badge_rewarder.rb @@ -56,7 +56,7 @@ def self.award_contributor_badges_from_github(since = 1.day.ago, message_markdow end def self.award_streak_badge(num_weeks) - article_user_ids = Article.where(published: true).where("published_at > ? AND score > ?", 1.week.ago, -25).pluck(:user_id) # No cred for super low quality + article_user_ids = Article.published.where("published_at > ? AND score > ?", 1.week.ago, -25).pluck(:user_id) # No cred for super low quality message = "Congrats on achieving this streak! Consistent writing is hard. The next streak badge you can get is the #{num_weeks * 2} Week Badge. 😉" users = User.where(id: article_user_ids).where("articles_count >= ?", num_weeks) usernames = [] diff --git a/app/labor/cache_buster.rb b/app/labor/cache_buster.rb index 24d3e68933a4e..c3f966fb51df0 100644 --- a/app/labor/cache_buster.rb +++ b/app/labor/cache_buster.rb @@ -13,7 +13,7 @@ def bust(path) end def bust_comment(commentable, username) - bust("/") if Article.where(published: true).order("hotness_score DESC").limit(3).pluck(:id).include?(commentable.id) + bust("/") if Article.published.order("hotness_score DESC").limit(3).pluck(:id).include?(commentable.id) if commentable.decorate.cached_tag_list_array.include?("discuss") && commentable.featured_number.to_i > 35.hours.ago.to_i bust("/") @@ -63,7 +63,7 @@ def bust_home_pages(article) CacheBuster.new.bust "/videos?i=i" end TIMEFRAMES.each do |timeframe| - if Article.where(published: true).where("published_at > ?", timeframe[0]). + if Article.published.where("published_at > ?", timeframe[0]). order("positive_reactions_count DESC").limit(3).pluck(:id).include?(article.id) bust("/top/#{timeframe[1]}") bust("/top/#{timeframe[1]}?i=i") @@ -74,7 +74,7 @@ def bust_home_pages(article) bust("/latest") bust("/latest?i=i") end - bust("/") if Article.where(published: true).order("hotness_score DESC").limit(4).pluck(:id).include?(article.id) + bust("/") if Article.published.order("hotness_score DESC").limit(4).pluck(:id).include?(article.id) end def bust_tag_pages(article) @@ -86,7 +86,7 @@ def bust_tag_pages(article) bust("/t/#{tag}/latest?i=i") end TIMEFRAMES.each do |timeframe| - if Article.where(published: true).where("published_at > ?", timeframe[0]).tagged_with(tag). + if Article.published.where("published_at > ?", timeframe[0]).tagged_with(tag). order("positive_reactions_count DESC").limit(3).pluck(:id).include?(article.id) bust("/top/#{timeframe[1]}") bust("/top/#{timeframe[1]}?i=i") @@ -97,7 +97,7 @@ def bust_tag_pages(article) end end if rand(2) == 1 && - Article.where(published: true).tagged_with(tag). + Article.published.tagged_with(tag). order("hotness_score DESC").limit(2).pluck(:id).include?(article.id) bust("/t/#{tag}") bust("/t/#{tag}?i=i") diff --git a/app/labor/email_logic.rb b/app/labor/email_logic.rb index e844b41caa6ae..0e594efac17c0 100644 --- a/app/labor/email_logic.rb +++ b/app/labor/email_logic.rb @@ -38,9 +38,9 @@ def get_articles_to_send order("score DESC"). limit(8) else - Article. + Article.published. where("published_at > ?", fresh_date). - where(published: true, featured: true, email_digest_eligible: true). + where(featured: true, email_digest_eligible: true). where.not(user_id: @user.id). where("score > ?", 25). order("score DESC"). diff --git a/app/labor/rate_limit_checker.rb b/app/labor/rate_limit_checker.rb index 0a46505568bd9..a57fbd8c183d5 100644 --- a/app/labor/rate_limit_checker.rb +++ b/app/labor/rate_limit_checker.rb @@ -9,9 +9,7 @@ def limit_by_situation(situation) when "comment_creation" user.comments.where("created_at > ?", 30.seconds.ago).size > 9 when "published_article_creation" - user.articles. - where(published: true). - where("created_at > ?", 30.seconds.ago).size > 9 + user.articles.published.where("created_at > ?", 30.seconds.ago).size > 9 else false end diff --git a/app/labor/sticky_article_collection.rb b/app/labor/sticky_article_collection.rb index 668acb731193a..dae2fe4e1541a 100644 --- a/app/labor/sticky_article_collection.rb +++ b/app/labor/sticky_article_collection.rb @@ -8,8 +8,7 @@ def initialize(article, author) end def user_stickies - author.articles. - where(published: true). + author.articles.published. limited_column_select. tagged_with(article_tags, any: true). where.not(id: article.id).order("published_at DESC"). @@ -21,10 +20,9 @@ def suggested_stickies end def tag_articles - @tag_articles ||= Article.tagged_with(article_tags, any: true). + @tag_articles ||= Article.published.tagged_with(article_tags, any: true). includes(:user). where("positive_reactions_count > ? OR comments_count > ?", reaction_count_num, comment_count_num). - where(published: true). where.not(id: article.id, user_id: article.user_id). where("featured_number > ?", 5.days.ago.to_i). order(Arel.sql("RANDOM()")). @@ -34,10 +32,9 @@ def tag_articles def more_articles return [] if tag_articles.size > 6 - Article.tagged_with(%w[career productivity discuss explainlikeimfive], any: true). + Article.published.tagged_with(%w[career productivity discuss explainlikeimfive], any: true). includes(:user). where("comments_count > ?", comment_count_num). - where(published: true). where.not(id: article.id, user_id: article.user_id). where("featured_number > ?", 5.days.ago.to_i). order(Arel.sql("RANDOM()")). diff --git a/app/labor/user_states.rb b/app/labor/user_states.rb index 10f2020c343aa..efe005fc6e374 100644 --- a/app/labor/user_states.rb +++ b/app/labor/user_states.rb @@ -19,7 +19,7 @@ def cached_onboarding_checklist end def made_first_article - user.articles.where(published: true).any? + user.articles.published.any? end def follows_a_tag diff --git a/app/models/article.rb b/app/models/article.rb index 05428360a25fe..547875517063f 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -66,10 +66,12 @@ class Article < ApplicationRecord serialize :ids_for_suggested_articles + scope :published, -> { where(published: true) } + scope :cached_tagged_with, ->(tag) { where("cached_tag_list ~* ?", "^#{tag},| #{tag},|, #{tag}$|^#{tag}$") } scope :active_help, lambda { - where(published: true). + published. cached_tagged_with("help"). order("created_at DESC"). where("published_at > ? AND comments_count < ?", 12.hours.ago, 6) @@ -195,8 +197,7 @@ def self.filter_excluded_tags(tag = nil) end def self.active_threads(tags = ["discuss"], time_ago = nil, number = 10) - stories = where(published: true). - limit(number) + stories = published.limit(number) stories = if time_ago == "latest" stories.order("published_at DESC").where("score > ?", -5) elsif time_ago @@ -211,7 +212,7 @@ def self.active_threads(tags = ["discuss"], time_ago = nil, number = 10) end def self.active_eli5(time_ago) - stories = where(published: true).cached_tagged_with("explainlikeimfive") + stories = published.cached_tagged_with("explainlikeimfive") stories = if time_ago == "latest" stories.order("published_at DESC").limit(3) @@ -363,11 +364,12 @@ def readable_publish_date def self.seo_boostable(tag = nil) if tag - Article.where(published: true). - cached_tagged_with(tag).order("organic_page_views_count DESC").limit(20).where("score > ?", 10). + Article.published. + cached_tagged_with(tag).order("organic_page_views_count DESC").where("score > ?", 10). + limit(20). pluck(:path, :title, :comments_count, :created_at) else - Article.where(published: true). + Article.published. order("organic_page_views_count DESC").limit(20).where("score > ?", 10). pluck(:path, :title, :comments_count, :created_at) end diff --git a/app/models/user.rb b/app/models/user.rb index 40446055edcf5..3dc2c1988429e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -232,11 +232,9 @@ def path end def followed_articles - Article.tagged_with(cached_followed_tag_names, any: true).union( - Article.where( - user_id: cached_following_users_ids, - ), - ).where(language: cached_preferred_langs, published: true) + Article.tagged_with(cached_followed_tag_names, any: true). + union(Article.where(user_id: cached_following_users_ids)). + where(language: cached_preferred_langs, published: true) end def cached_following_users_ids diff --git a/app/services/analytics_service.rb b/app/services/analytics_service.rb index 1ad53fcff9bc0..043b0bda57c3b 100644 --- a/app/services/analytics_service.rb +++ b/app/services/analytics_service.rb @@ -72,13 +72,13 @@ def stats_grouped_by_day attr_reader :user_or_org, :start_date, :end_date, :article_data, :reaction_data, :comment_data, :follow_data, :page_view_data def load_data + @article_data = Article.published.where("#{user_or_org.class.name.downcase}_id" => user_or_org.id) if @article_id - @article_data = Article.where(id: @article_id, published: true, "#{user_or_org.class.name.downcase}_id" => user_or_org.id) + @article_data = @article_data.where(id: @article_id) raise UnauthorizedError if @article_data.blank? article_ids = @article_id else - @article_data = Article.where("#{user_or_org.class.name.downcase}_id" => user_or_org.id, published: true) article_ids = @article_data.pluck(:id) end diff --git a/app/services/article_api_index_service.rb b/app/services/article_api_index_service.rb index 9f7a0b736516a..b883d8b3e4b12 100644 --- a/app/services/article_api_index_service.rb +++ b/app/services/article_api_index_service.rb @@ -33,15 +33,13 @@ def username_articles end if (user = User.find_by(username: username)) - user.articles. - where(published: true). + user.articles.published. includes(:user). order("published_at DESC"). page(page). per(num) elsif (organization = Organization.find_by(slug: username)) - organization.articles. - where(published: true). + organization.articles.published. includes(:user). order("published_at DESC"). page(page). @@ -52,53 +50,35 @@ def username_articles end def tag_articles - if Tag.find_by(name: tag)&.requires_approval - Article. - where(published: true, approved: true). - order("featured_number DESC"). - includes(:user). - includes(:organization). - page(page). - per(30). - cached_tagged_with(tag) - elsif top.present? - Article. - where(published: true). - order("positive_reactions_count DESC"). - where("published_at > ?", top.to_i.days.ago). - includes(:user). - includes(:organization). - page(page). - per(30). - cached_tagged_with(tag) - else - Article. - where(published: true). - order("hotness_score DESC"). - includes(:user). - includes(:organization). - page(page). - per(30). - cached_tagged_with(tag) - end + articles = Article.published.cached_tagged_with(tag).includes(:user, :organization) + + articles = if Tag.find_by(name: tag)&.requires_approval + articles.where(approved: true).order("featured_number DESC") + elsif top.present? + articles.where("published_at > ?", top.to_i.days.ago). + order("positive_reactions_count DESC") + else + articles.order("hotness_score DESC") + end + + articles.page(page).per(30) end def state_articles(state) if state == "fresh" - Article.where(published: true). + Article.published. where("positive_reactions_count < ? AND featured_number > ? AND score > ?", 2, 7.hours.ago.to_i, -2) elsif state == "rising" - Article.where(published: true). + Article.published. where("positive_reactions_count > ? AND positive_reactions_count < ? AND featured_number > ?", 19, 33, 3.days.ago.to_i) end end def base_articles - Article. - where(published: true, featured: true). + Article.published. + where(featured: true). + includes(:user, :organization). order("hotness_score DESC"). - includes(:user). - includes(:organization). page(page). per(30) end diff --git a/app/services/suggester/articles/classic.rb b/app/services/suggester/articles/classic.rb index a07496272c367..e84b026cd4b09 100644 --- a/app/services/suggester/articles/classic.rb +++ b/app/services/suggester/articles/classic.rb @@ -21,12 +21,11 @@ def get(num = 1) def qualifying_articles(tag_names) tag_name = tag_names.sample - Rails.cache. - fetch("classic-article-for-tag-#{tag_name}}", expires_in: 90.minutes) do - Article.cached_tagged_with(tag_name). + Rails.cache.fetch("classic-article-for-tag-#{tag_name}}", expires_in: 90.minutes) do + Article.published.cached_tagged_with(tag_name). includes(:user). limited_column_select. - where(published: true, featured: true). + where(featured: true). where("positive_reactions_count > ?", MIN_REACTION_COUNT). where("published_at > ?", 10.months.ago). order(Arel.sql("RANDOM()")) diff --git a/app/services/suggester/articles/high_quality.rb b/app/services/suggester/articles/high_quality.rb index fab38b4769d6a..e3237a1a01cae 100644 --- a/app/services/suggester/articles/high_quality.rb +++ b/app/services/suggester/articles/high_quality.rb @@ -8,12 +8,12 @@ def initialize(options = {}) end def suggest(num) - Article.where(published: true, featured: true). + Article.published.where(featured: true). includes(:user). - where("positive_reactions_count > ?", MIN_HQ_REACTION_COUNT). - order(Arel.sql("RANDOM()")). limited_column_select. + where("positive_reactions_count > ?", MIN_HQ_REACTION_COUNT). where.not(id: @not_ids). + order(Arel.sql("RANDOM()")). limit(num) end end diff --git a/app/services/suggester/users/recent.rb b/app/services/suggester/users/recent.rb index 59ed3e5c02075..a7b570b0e9109 100644 --- a/app/services/suggester/users/recent.rb +++ b/app/services/suggester/users/recent.rb @@ -20,11 +20,9 @@ def suggest private def tagged_article_user_ids(num_weeks = 1) - Article. + Article.published. tagged_with(user.decorate.cached_followed_tag_names, any: true). - where(published: true). - where("score > ? AND published_at > ?", - article_reaction_count, num_weeks.weeks.ago). + where("score > ? AND published_at > ?", article_reaction_count, num_weeks.weeks.ago). pluck(:user_id). each_with_object(Hash.new(0)) { |value, counts| counts[value] += 1 }. sort_by { |_key, value| value }. diff --git a/app/services/suggester/users/sidebar.rb b/app/services/suggester/users/sidebar.rb index 784c7b48f0969..74fd22b3fa37e 100644 --- a/app/services/suggester/users/sidebar.rb +++ b/app/services/suggester/users/sidebar.rb @@ -10,16 +10,17 @@ def initialize(user, given_tag) def suggest Rails.cache.fetch(generate_cache_name, expires_in: 120.hours) do reaction_count = Rails.env.production? ? 25 : 0 - user_ids = Article.tagged_with([given_tag], any: true). - where(published: true). + user_ids = Article.published.tagged_with([given_tag], any: true). where("positive_reactions_count > ?", reaction_count). where("published_at > ?", 4.months.ago). where("user_id != ?", user.id). - where.not(user_id: user.following_by_type("User"). - pluck(:id)).pluck(:user_id) - group_one = User.select(:id, :name, :username, :profile_image, :summary).where(id: user_ids). + where.not(user_id: user.following_by_type("User").pluck(:id)). + pluck(:user_id) + group_one = User.select(:id, :name, :username, :profile_image, :summary). + where(id: user_ids). order("reputation_modifier DESC").limit(20).to_a - group_two = User.select(:id, :name, :username, :profile_image, :summary).where(id: user_ids). + group_two = User.select(:id, :name, :username, :profile_image, :summary). + where(id: user_ids). order(Arel.sql("RANDOM()")).limit(20).to_a (group_one + group_two).uniq end diff --git a/app/views/articles/_collection.html.erb b/app/views/articles/_collection.html.erb index 5fb45aff7106a..7c5e14457d8c2 100644 --- a/app/views/articles/_collection.html.erb +++ b/app/views/articles/_collection.html.erb @@ -1,5 +1,5 @@ <% @collection = @article.collection %> -<% if @collection.present? && @collection.articles.where(published: true).size > 1 %> +<% if @collection.present? && @collection.articles.published.size > 1 %>
<% if @collection.slug.present? %>

Part of "<%= @collection.slug %>" series

@@ -7,7 +7,7 @@

Part of a series

<% end %>
- <% @collection.articles.where(published: true).order("published_at ASC").each_with_index do |article, i| %> + <% @collection.articles.published.order("published_at ASC").each_with_index do |article, i| %>
Latest Posts
-<% Article.tagged_with("shecoded").where(approved: true, published: true).order("created_at DESC").limit(8).each do |article| %> +<% Article.published.tagged_with("shecoded").where(approved: true).order("created_at DESC").limit(8).each do |article| %>
@@ -19,7 +19,7 @@ " style="cursor:pointer;min-height:136px;background:#0e0e0e" alt="she coded" />
View - All <%= Article.tagged_with("shecoded").where(approved: true, published: true).size %> Submissions + All <%= Article.published.tagged_with("shecoded").where(approved: true).size %> Submissions
diff --git a/app/views/articles/tags/_sidebar.html.erb b/app/views/articles/tags/_sidebar.html.erb index 9709dbf1ae06e..629d3f13d782e 100644 --- a/app/views/articles/tags/_sidebar.html.erb +++ b/app/views/articles/tags/_sidebar.html.erb @@ -1,4 +1,4 @@ -<% cache "tag-sidebar-#{@tag}-#{@tag_model&.updated_at}-#{@tag_model&.taggings_count}", expires_in: 5.hour do %> +<% cache "tag-sidebar-#{@tag}-#{@tag_model&.updated_at}-#{@tag_model&.taggings_count}", expires_in: 5.hours do %>