diff --git a/app/controllers/chat_channels_controller.rb b/app/controllers/chat_channels_controller.rb index f3fae43c3..f93aff92c 100644 --- a/app/controllers/chat_channels_controller.rb +++ b/app/controllers/chat_channels_controller.rb @@ -175,7 +175,7 @@ class ChatChannelsController < ApplicationController .where(show_global_badge_notification: true) .where.not(status: %w[removed_from_channel left_channel]) .includes(%i[chat_channel user]) - .order("chat_channel_memberships.updated_at DESC") + .order("chat_channel_memberships.updated_at" => :desc) else [] end @@ -187,7 +187,7 @@ class ChatChannelsController < ApplicationController current_user .chat_channel_memberships.includes(:chat_channel) .where(status: "pending") - .order("chat_channel_memberships.updated_at DESC") + .order("chat_channel_memberships.updated_at" => :desc) else [] end diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index 0749b879b..23b499f5e 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -36,27 +36,27 @@ class DashboardsController < ApplicationController def following_tags @followed_tags = @user.follows_by_type("ActsAsTaggableOn::Tag") - .order("points DESC").includes(:followable).limit(@follows_limit) + .order(points: :desc).includes(:followable).limit(@follows_limit) end def following_users @follows = @user.follows_by_type("User") - .order("created_at DESC").includes(:followable).limit(@follows_limit) + .order(created_at: :desc).includes(:followable).limit(@follows_limit) end def following_organizations @followed_organizations = @user.follows_by_type("Organization") - .order("created_at DESC").includes(:followable).limit(@follows_limit) + .order(created_at: :desc).includes(:followable).limit(@follows_limit) end def following_podcasts @followed_podcasts = @user.follows_by_type("Podcast") - .order("created_at DESC").includes(:followable).limit(@follows_limit) + .order(created_at: :desc).includes(:followable).limit(@follows_limit) end def followers @follows = Follow.followable_user(@user.id) - .includes(:follower).order("created_at DESC").limit(@follows_limit) + .includes(:follower).order(created_at: :desc).limit(@follows_limit) end def pro diff --git a/app/controllers/email_authorizations_controller.rb b/app/controllers/email_authorizations_controller.rb index ae71e0fec..6752b4ffb 100644 --- a/app/controllers/email_authorizations_controller.rb +++ b/app/controllers/email_authorizations_controller.rb @@ -5,7 +5,7 @@ class EmailAuthorizationsController < ApplicationController user = User.find_by(username: params[:username]) raise ActionController::RoutingError, "Not Found" unless current_user == user - email_authorization = user.email_authorizations.order("created_at DESC").first + email_authorization = user.email_authorizations.order(created_at: :desc).first correct_token = email_authorization.confirmation_token == params[:confirmation_token] raise ActionController::RoutingError, "Not Found" unless correct_token diff --git a/app/controllers/internal/articles_controller.rb b/app/controllers/internal/articles_controller.rb index f990e5a20..104b9ea6c 100644 --- a/app/controllers/internal/articles_controller.rb +++ b/app/controllers/internal/articles_controller.rb @@ -57,7 +57,7 @@ module Internal .where("published_at > ? OR crossposted_at > ?", days_ago.days.ago, days_ago.days.ago) .includes(:user) .limited_columns_internal_select - .order("public_reactions_count DESC") + .order(public_reactions_count: :desc) .page(params[:page]) .per(50) end @@ -67,7 +67,7 @@ module Internal .where("published_at > ?", months_ago) .includes(user: [:notes]) .limited_columns_internal_select - .order("public_reactions_count DESC") + .order(public_reactions_count: :desc) .page(params[:page]) .per(50) end @@ -77,7 +77,7 @@ module Internal .includes(:user, :buffer_updates) .tagged_with(Tag.bufferized_tags, any: true) .limited_columns_internal_select - .order("hotness_score DESC") + .order(hotness_score: :desc) .page(params[:page]) .per(60) end @@ -86,7 +86,7 @@ module Internal Article.boosted_via_additional_articles .includes(:user, :buffer_updates) .limited_columns_internal_select - .order("published_at DESC") + .order(published_at: :desc) .page(params[:page]) .per(100) end @@ -95,7 +95,7 @@ module Internal Article.published .includes(user: [:notes]) .limited_columns_internal_select - .order("published_at DESC") + .order(published_at: :desc) .page(params[:page]) .per(50) end @@ -104,7 +104,7 @@ module Internal Article.published .includes(user: [:notes]) .limited_columns_internal_select - .order("hotness_score DESC") + .order(hotness_score: :desc) .page(params[:page]) .per(30) end @@ -115,7 +115,7 @@ module Internal .where("featured_number > ?", Time.current.to_i) .includes(:user, :buffer_updates) .limited_columns_internal_select - .order("featured_number DESC") + .order(featured_number: :desc) end def article_params diff --git a/app/controllers/internal/comments_controller.rb b/app/controllers/internal/comments_controller.rb index 1a2d7cb5f..d3ba5e54b 100644 --- a/app/controllers/internal/comments_controller.rb +++ b/app/controllers/internal/comments_controller.rb @@ -7,14 +7,14 @@ module Internal Comment .includes(:user) .includes(:commentable) - .order("public_reactions_count DESC") + .order(public_reactions_count: :desc) .where("created_at > ?", params[:state].split("-").last.to_i.days.ago) .page(params[:page] || 1).per(50) else Comment .includes(:user) .includes(:commentable) - .order("created_at DESC") + .order(created_at: :desc) .page(params[:page] || 1).per(50) end end diff --git a/app/controllers/internal/events_controller.rb b/app/controllers/internal/events_controller.rb index f94cc8352..b0d2a3c8a 100644 --- a/app/controllers/internal/events_controller.rb +++ b/app/controllers/internal/events_controller.rb @@ -9,12 +9,12 @@ module Internal location_url: app_url, description_markdown: "*Description* *Pre-requisites:* *Bio*", ) - @events = Event.order("starts_at DESC") + @events = Event.order(starts_at: :desc) end def create @event = Event.new(event_params) - @events = Event.order("starts_at DESC") + @events = Event.order(starts_at: :desc) if @event.save flash[:success] = "Successfully created event: #{@event.title}" redirect_to(action: :index) @@ -26,7 +26,7 @@ module Internal def update @event = Event.find(params[:id]) - @events = Event.order("starts_at DESC") + @events = Event.order(starts_at: :desc) if @event.update(event_params) flash[:success] = "#{@event.title} was successfully updated" redirect_to "/internal/events" diff --git a/app/controllers/internal/listings_controller.rb b/app/controllers/internal/listings_controller.rb index c9c8a62e5..9f098f4d2 100644 --- a/app/controllers/internal/listings_controller.rb +++ b/app/controllers/internal/listings_controller.rb @@ -9,7 +9,7 @@ module Internal def index @listings = Listing.includes(%i[user listing_category]) - .page(params[:page]).order("bumped_at DESC").per(50) + .page(params[:page]).order(bumped_at: :desc).per(50) @listings = @listings.published unless include_unpublished? @listings = @listings.in_category(params[:filter]) if params[:filter].present? diff --git a/app/controllers/internal/podcasts_controller.rb b/app/controllers/internal/podcasts_controller.rb index 942ebe7c3..107b877f9 100644 --- a/app/controllers/internal/podcasts_controller.rb +++ b/app/controllers/internal/podcasts_controller.rb @@ -8,7 +8,7 @@ module Internal def index @podcasts = Podcast.left_outer_joins(:podcast_episodes) .select("podcasts.*, count(podcast_episodes) as episodes_count") - .group("podcasts.id").order("podcasts.created_at DESC") + .group("podcasts.id").order("podcasts.created_at" => :desc) .page(params[:page]).per(50) return if params[:search].blank? diff --git a/app/controllers/internal/privileged_reactions_controller.rb b/app/controllers/internal/privileged_reactions_controller.rb index 2906d2b8e..7f3409922 100644 --- a/app/controllers/internal/privileged_reactions_controller.rb +++ b/app/controllers/internal/privileged_reactions_controller.rb @@ -9,7 +9,7 @@ module Internal .includes(:user, :reactable) .where("category IN (?)", PRIVILEGED_REACTION_CATEGORIES) - .order("reactions.created_at DESC") + .order("reactions.created_at" => :desc) .ransack(params[:q]) @privileged_reactions = @q.result.page(params[:page] || 1).per(25) end diff --git a/app/controllers/internal/sponsorships_controller.rb b/app/controllers/internal/sponsorships_controller.rb index c0320f054..483ad8cf2 100644 --- a/app/controllers/internal/sponsorships_controller.rb +++ b/app/controllers/internal/sponsorships_controller.rb @@ -3,7 +3,7 @@ module Internal layout "internal" def index - @sponsorships = Sponsorship.includes(:organization, :user).order("created_at desc").page(params[:page]).per(50) + @sponsorships = Sponsorship.includes(:organization, :user).order(created_at: :desc).page(params[:page]).per(50) end def edit diff --git a/app/controllers/internal/tags_controller.rb b/app/controllers/internal/tags_controller.rb index 87c412aa9..3afbdb117 100644 --- a/app/controllers/internal/tags_controller.rb +++ b/app/controllers/internal/tags_controller.rb @@ -9,11 +9,11 @@ module Internal def index @tags = case params[:state] when "supported" - Tag.where(supported: true).order("taggings_count DESC").page(params[:page]).per(50) + Tag.where(supported: true).order(taggings_count: :desc).page(params[:page]).per(50) when "unsupported" - Tag.where(supported: false).order("taggings_count DESC").page(params[:page]).per(50) + Tag.where(supported: false).order(taggings_count: :desc).page(params[:page]).per(50) else - Tag.order("taggings_count DESC").page(params[:page]).per(50) + Tag.order(taggings_count: :desc).page(params[:page]).per(50) end @tags = @tags.where("tags.name ILIKE :search", search: "%#{params[:search]}%") if params[:search].present? end diff --git a/app/controllers/internal/users_controller.rb b/app/controllers/internal/users_controller.rb index 8f30eb027..5c958cc98 100644 --- a/app/controllers/internal/users_controller.rb +++ b/app/controllers/internal/users_controller.rb @@ -23,11 +23,11 @@ module Internal @notes = @user.notes.order(created_at: :desc).limit(10) @organization_memberships = @user.organization_memberships .joins(:organization) - .order("organizations.name ASC") + .order("organizations.name" => :asc) .includes(:organization) @last_email_verification_date = @user.email_authorizations .where.not(verified_at: nil) - .order("created_at DESC").first&.verified_at || "Never" + .order(created_at: :desc).first&.verified_at || "Never" end def update diff --git a/app/controllers/internal/webhook_endpoints_controller.rb b/app/controllers/internal/webhook_endpoints_controller.rb index 5e806f2b5..e1a3a7f6d 100644 --- a/app/controllers/internal/webhook_endpoints_controller.rb +++ b/app/controllers/internal/webhook_endpoints_controller.rb @@ -5,7 +5,7 @@ module Internal def index @endpoints = Webhook::Endpoint.includes(:user) .page(params[:page]).per(50) - .order("created_at desc") + .order(created_at: :desc) end end end diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index 3157533dc..1238234b8 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -39,7 +39,7 @@ class ListingsController < ApplicationController @listings = if params[:category].blank? published_listings - .order("bumped_at DESC") + .order(bumped_at: :desc) .includes(:user, :organization, :taggings) .limit(12) else diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index 921d5cc21..c3bda1a6f 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -14,7 +14,7 @@ class ModerationsController < ApplicationController articles = Article.published .where("score > -5 AND score < 5") - .order("published_at DESC").limit(70) + .order(published_at: :desc).limit(70) articles = articles.cached_tagged_with(params[:tag]) if params[:tag].present? if params[:state] == "new-authors" articles = articles.where("nth_published_by_author > 0 AND nth_published_by_author < 4 AND published_at > ?", diff --git a/app/controllers/page_views_controller.rb b/app/controllers/page_views_controller.rb index c2350db04..54199c505 100644 --- a/app/controllers/page_views_controller.rb +++ b/app/controllers/page_views_controller.rb @@ -19,7 +19,7 @@ class PageViewsController < ApplicationMetalController def update if session_current_user_id - page_view = PageView.order("created_at DESC").find_or_create_by(article_id: params[:id], + page_view = PageView.order(created_at: :desc).find_or_create_by(article_id: params[:id], user_id: session_current_user_id) unless page_view.new_record? page_view.update_column(:time_tracked_in_seconds, page_view.time_tracked_in_seconds + 15) diff --git a/app/controllers/podcast_episodes_controller.rb b/app/controllers/podcast_episodes_controller.rb index ddf5c7abf..5f7f6e648 100644 --- a/app/controllers/podcast_episodes_controller.rb +++ b/app/controllers/podcast_episodes_controller.rb @@ -5,10 +5,10 @@ class PodcastEpisodesController < ApplicationController def index @podcast_index = true - @podcasts = Podcast.available.order("title asc") + @podcasts = Podcast.available.order(title: :asc) @podcast_episodes = PodcastEpisodeDecorator.decorate_collection(PodcastEpisode .available - .includes(:podcast).order("published_at desc").first(20)) + .includes(:podcast).order(published_at: :desc).first(20)) if params[:q].blank? surrogate_keys = ["podcast_episodes_all"] + @podcast_episodes.map(&:record_key) diff --git a/app/controllers/podcasts_controller.rb b/app/controllers/podcasts_controller.rb index a37cf8156..8b7c7582a 100644 --- a/app/controllers/podcasts_controller.rb +++ b/app/controllers/podcasts_controller.rb @@ -9,7 +9,7 @@ class PodcastsController < ApplicationController def new @podcast = Podcast.new - @podcasts = Podcast.available.order("title asc") + @podcasts = Podcast.available.order(title: :asc) @podcast_index = true end diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index fdffd5548..2253182e5 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -71,7 +71,7 @@ class StoriesController < ApplicationController def get_latest_campaign_articles campaign_articles_scope = Article.tagged_with(Campaign.current.featured_tags, any: true) .where("published_at > ? AND score > ?", 4.weeks.ago, 0) - .order("hotness_score DESC") + .order(hotness_score: :desc) requires_approval = Campaign.current.articles_require_approval? campaign_articles_scope = campaign_articles_scope.where(approved: true) if requires_approval @@ -195,7 +195,7 @@ class StoriesController < ApplicationController @podcast_index = true @list_of = "podcast-episodes" @podcast_episodes = @podcast.podcast_episodes - .reachable.order("published_at DESC").limit(30).decorate + .reachable.order(published_at: :desc).limit(30).decorate set_surrogate_key_header "podcast_episodes" render template: "podcast_episodes/index" end @@ -204,7 +204,7 @@ class StoriesController < ApplicationController @user = @organization @stories = ArticleDecorator.decorate_collection(@organization.articles.published .limited_column_select - .order("published_at DESC").page(@page).per(8)) + .order(published_at: :desc).page(@page).per(8)) @organization_article_index = true set_organization_json_ld set_surrogate_key_header "articles-org-#{@organization.id}" @@ -314,7 +314,7 @@ class StoriesController < ApplicationController comment_count = params[:view] == "comments" ? 250 : 8 @comments = if @user.comments_count.positive? @user.comments.where(deleted: false) - .order("created_at DESC").includes(:commentable).limit(comment_count) + .order(created_at: :desc).includes(:commentable).limit(comment_count) else [] end @@ -323,11 +323,11 @@ class StoriesController < ApplicationController def assign_user_stories @pinned_stories = Article.published.where(id: @user.profile_pins.select(:pinnable_id)) .limited_column_select - .order("published_at DESC").decorate + .order(published_at: :desc).decorate @stories = ArticleDecorator.decorate_collection(@user.articles.published .limited_column_select .where.not(id: @pinned_stories.pluck(:id)) - .order("published_at DESC").page(@page).per(user_signed_in? ? 2 : SIGNED_OUT_RECORD_COUNT)) + .order(published_at: :desc).page(@page).per(user_signed_in? ? 2 : SIGNED_OUT_RECORD_COUNT)) end def assign_user_github_repositories @@ -337,11 +337,11 @@ class StoriesController < ApplicationController def stories_by_timeframe if %w[week month year infinity].include?(params[:timeframe]) @stories.where("published_at > ?", Timeframer.new(params[:timeframe]).datetime) - .order("public_reactions_count DESC") + .order(public_reactions_count: :desc) elsif params[:timeframe] == "latest" - @stories.where("score > ?", -20).order("published_at DESC") + @stories.where("score > ?", -20).order(published_at: :desc) else - @stories.order("hotness_score DESC").where("score > 2") + @stories.order(hotness_score: :desc).where("score > 2") end end @@ -351,7 +351,7 @@ class StoriesController < ApplicationController num_hours = Rails.env.production? ? 24 : 2400 @podcast_episodes = PodcastEpisode .includes(:podcast) - .order("published_at desc") + .order(published_at: :desc) .where("published_at > ?", num_hours.hours.ago) .select(:slug, :title, :podcast_id, :image) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cf5d5af7f..2be8765e5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -304,7 +304,7 @@ class UsersController < ApplicationController end def handle_organization_tab - @organizations = @current_user.organizations.order("name ASC") + @organizations = @current_user.organizations.order(name: :asc) if params[:org_id] == "new" || params[:org_id].blank? && @organizations.size.zero? @organization = Organization.new elsif params[:org_id].blank? || params[:org_id].match?(/\d/) diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb index 2816c0b1c..25ccf8218 100644 --- a/app/controllers/videos_controller.rb +++ b/app/controllers/videos_controller.rb @@ -9,7 +9,7 @@ class VideosController < ApplicationController @video_articles = Article.with_video .includes([:user]) .select(:id, :video, :path, :title, :video_thumbnail_url, :user_id, :video_duration_in_seconds) - .order("hotness_score DESC") + .order(hotness_score: :desc) .page(params[:page].to_i).per(24) set_surrogate_key_header "videos", Article.table_key, @video_articles.map(&:record_key) diff --git a/app/labor/article_suggester.rb b/app/labor/article_suggester.rb index aedc60237..e1c59df7a 100644 --- a/app/labor/article_suggester.rb +++ b/app/labor/article_suggester.rb @@ -31,7 +31,7 @@ class ArticleSuggester Article.published .where.not(id: ids_to_ignore) .where.not(user_id: article.user_id) - .order("hotness_score DESC") + .order(hotness_score: :desc) .offset(rand(0..offset)) .first(max) end @@ -40,7 +40,7 @@ class ArticleSuggester Article.published.tagged_with(cached_tag_list_array, any: true) .where.not(user_id: article.user_id) .where("organic_page_views_past_month_count > 5") - .order("hotness_score DESC") + .order(hotness_score: :desc) .offset(rand(0..offset)) .first(max) end diff --git a/app/labor/cache_buster.rb b/app/labor/cache_buster.rb index 41bd93d59..51804cca1 100644 --- a/app/labor/cache_buster.rb +++ b/app/labor/cache_buster.rb @@ -77,7 +77,7 @@ module CacheBuster end TIMEFRAMES.each do |timestamp, interval| if Article.published.where("published_at > ?", timestamp) - .order("public_reactions_count DESC").limit(3).pluck(:id).include?(article.id) + .order(public_reactions_count: :desc).limit(3).pluck(:id).include?(article.id) bust("/top/#{interval}") bust("/top/#{interval}?i=i") bust("/top/#{interval}/?i=i") @@ -87,7 +87,7 @@ module CacheBuster bust("/latest") bust("/latest?i=i") end - bust("/") if Article.published.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 self.bust_tag_pages(article) @@ -100,7 +100,7 @@ module CacheBuster end TIMEFRAMES.each do |timestamp, interval| if Article.published.where("published_at > ?", timestamp).tagged_with(tag) - .order("public_reactions_count DESC").limit(3).pluck(:id).include?(article.id) + .order(public_reactions_count: :desc).limit(3).pluck(:id).include?(article.id) bust("/top/#{interval}") bust("/top/#{interval}?i=i") bust("/top/#{interval}/?i=i") @@ -111,7 +111,7 @@ module CacheBuster end if rand(2) == 1 && Article.published.tagged_with(tag) - .order("hotness_score DESC").limit(2).pluck(:id).include?(article.id) + .order(hotness_score: :desc).limit(2).pluck(:id).include?(article.id) bust("/t/#{tag}") bust("/t/#{tag}?i=i") end @@ -195,7 +195,7 @@ module CacheBuster # bust commentable if it's an article def self.bust_article_comment(commentable) - bust("/") if Article.published.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("/") diff --git a/app/labor/email_logic.rb b/app/labor/email_logic.rb index 86b652136..a1c682e69 100644 --- a/app/labor/email_logic.rb +++ b/app/labor/email_logic.rb @@ -40,7 +40,7 @@ class EmailLogic .where("score > ?", 12) .where("experience_level_rating > ? AND experience_level_rating < ?", experience_level_rating_min, experience_level_rating_max) - .order("score DESC") + .order(score: :desc) .limit(8) else Article.published @@ -48,7 +48,7 @@ class EmailLogic .where(featured: true, email_digest_eligible: true) .where.not(user_id: @user.id) .where("score > ?", 25) - .order("score DESC") + .order(score: :desc) .limit(8) end diff --git a/app/labor/reading_list.rb b/app/labor/reading_list.rb index 978ed0902..c33f92b60 100644 --- a/app/labor/reading_list.rb +++ b/app/labor/reading_list.rb @@ -10,7 +10,7 @@ class ReadingList .joins(:reactions) .includes(:user) .where(reactions: reaction_criteria) - .order("reactions.created_at DESC") + .order("reactions.created_at" => :desc) end def cached_ids_of_articles @@ -20,7 +20,7 @@ class ReadingList end def ids_of_articles - Reaction.where(reaction_criteria).order("created_at DESC").pluck(:reactable_id) + Reaction.where(reaction_criteria).order(created_at: :desc).pluck(:reactable_id) end def count diff --git a/app/labor/sticky_article_collection.rb b/app/labor/sticky_article_collection.rb index 990e77be0..09e526e48 100644 --- a/app/labor/sticky_article_collection.rb +++ b/app/labor/sticky_article_collection.rb @@ -12,7 +12,7 @@ class StickyArticleCollection author.articles.published .limited_column_select .tagged_with(article_tags, any: true) - .where.not(id: article.id).order("published_at DESC") + .where.not(id: article.id).order(published_at: :desc) .limit(3) end diff --git a/app/models/article.rb b/app/models/article.rb index 5f7624a03..99c91bcbc 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -34,7 +34,7 @@ class Article < ApplicationRecord where( "comments.score > ? AND ancestry IS NULL and hidden_by_commentable_user is FALSE and deleted is FALSE", 10, - ).order("comments.score DESC") + ).order("comments.score" => :desc) }, as: :commentable, inverse_of: :commentable, @@ -199,12 +199,12 @@ class Article < ApplicationRecord def self.active_threads(tags = ["discuss"], time_ago = nil, number = 10) stories = published.limit(number) stories = if time_ago == "latest" - stories.order("published_at DESC").where("score > ?", -5) + stories.order(published_at: :desc).where("score > ?", -5) elsif time_ago - stories.order("comments_count DESC") + stories.order(comments_count: :desc) .where("published_at > ? AND score > ?", time_ago, -5) else - stories.order("last_comment_at DESC") + stories.order(last_comment_at: :desc) .where("published_at > ? AND score > ?", (tags.present? ? 5 : 2).days.ago, -5) end stories = tags.size == 1 ? stories.cached_tagged_with(tags.first) : stories.tagged_with(tags) diff --git a/app/models/chat_channel.rb b/app/models/chat_channel.rb index 82cc4f3b1..5f96b6c89 100644 --- a/app/models/chat_channel.rb +++ b/app/models/chat_channel.rb @@ -180,7 +180,7 @@ class ChatChannel < ApplicationRecord def channel_human_names active_memberships - .order("last_opened_at DESC").limit(5).includes(:user).map do |membership| + .order(last_opened_at: :desc).limit(5).includes(:user).map do |membership| membership.user.name end end diff --git a/app/models/html_variant.rb b/app/models/html_variant.rb index c471566bc..256151ee6 100644 --- a/app/models/html_variant.rb +++ b/app/models/html_variant.rb @@ -37,7 +37,7 @@ class HtmlVariant < ApplicationRecord def find_top_for_test(tags_array, group) where(group: group, approved: true, published: true, target_tag: tags_array) - .order("success_rate DESC").limit(rand(1..20)).sample + .order(success_rate: :desc).limit(rand(1..20)).sample end def find_random_for_test(tags_array, group) diff --git a/app/models/message.rb b/app/models/message.rb index b8c79c252..a3b8d0e55 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -224,7 +224,7 @@ class Message < ApplicationRecord recipient = direct_receiver return if !chat_channel.direct? || recipient.updated_at > 1.hour.ago || - recipient.chat_channel_memberships.order("last_opened_at DESC") + recipient.chat_channel_memberships.order(last_opened_at: :desc) .first.last_opened_at > 15.hours.ago || chat_channel.last_message_at > 30.minutes.ago || recipient.email_connect_messages == false diff --git a/app/models/tag.rb b/app/models/tag.rb index 0dff0e86d..e81872a8a 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -53,7 +53,7 @@ class Tag < ActsAsTaggableOn::Tag end def tag_moderator_ids - User.with_role(:tag_moderator, self).order("id ASC").pluck(:id) + User.with_role(:tag_moderator, self).order(id: :asc).pluck(:id) end def self.bufferized_tags diff --git a/app/queries/internal/moderators_query.rb b/app/queries/internal/moderators_query.rb index 67ee41cd6..ea0c24120 100644 --- a/app/queries/internal/moderators_query.rb +++ b/app/queries/internal/moderators_query.rb @@ -12,7 +12,7 @@ module Internal relation.where( "id NOT IN (SELECT user_id FROM users_roles WHERE role_id = ?)", role_id_for(:trusted), - ).order("users.comments_count DESC") + ).order("users.comments_count" => :desc) else relation.joins(:roles) .where(users_roles: { role_id: role_id_for(state) }) diff --git a/app/queries/internal/users_query.rb b/app/queries/internal/users_query.rb index a35654816..bdb1f8efb 100644 --- a/app/queries/internal/users_query.rb +++ b/app/queries/internal/users_query.rb @@ -6,7 +6,7 @@ module Internal relation = relation.with_role(role, :any) if role.presence relation = search_relation(relation, search) if search.presence - relation.order("created_at DESC") + relation.order(created_at: :desc) end def self.search_relation(relation, search) diff --git a/app/services/article_api_index_service.rb b/app/services/article_api_index_service.rb index f848d4cc1..9671eb0e0 100644 --- a/app/services/article_api_index_service.rb +++ b/app/services/article_api_index_service.rb @@ -42,13 +42,13 @@ class ArticleApiIndexService if (user = User.find_by(username: username)) user.articles.published .includes(:organization) - .order("published_at DESC") + .order(published_at: :desc) .page(page) .per(per_page || num) elsif (organization = Organization.find_by(slug: username)) organization.articles.published .includes(:user) - .order("published_at DESC") + .order(published_at: :desc) .page(page) .per(per_page || num) else @@ -60,12 +60,12 @@ class ArticleApiIndexService 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") + articles.where(approved: true).order(featured_number: :desc) elsif top.present? articles.where("published_at > ?", top.to_i.days.ago) - .order("public_reactions_count DESC") + .order(public_reactions_count: :desc) else - articles.order("hotness_score DESC") + articles.order(hotness_score: :desc) end articles.page(page).per(per_page || DEFAULT_PER_PAGE) @@ -74,7 +74,7 @@ class ArticleApiIndexService def top_articles Article.published.includes(:user, :organization) .where("published_at > ?", top.to_i.days.ago) - .order("public_reactions_count DESC") + .order(public_reactions_count: :desc) .page(page).per(per_page || DEFAULT_PER_PAGE) end @@ -102,7 +102,7 @@ class ArticleApiIndexService Article.published .where(collection_id: collection_id) .includes(:user, :organization) - .order("published_at") + .order(:published_at) .page(page) .per(per_page || DEFAULT_PER_PAGE) end @@ -111,7 +111,7 @@ class ArticleApiIndexService Article.published .where(featured: true) .includes(:user, :organization) - .order("hotness_score DESC") + .order(hotness_score: :desc) .page(page) .per(per_page || DEFAULT_PER_PAGE) end diff --git a/app/services/articles/feed.rb b/app/services/articles/feed.rb index ea552b474..73465d753 100644 --- a/app/services/articles/feed.rb +++ b/app/services/articles/feed.rb @@ -37,11 +37,11 @@ module Articles # Timeframe values from Timeframer::DATETIMES def top_articles_by_timeframe(timeframe:) published_articles_by_tag.where("published_at > ?", Timeframer.new(timeframe).datetime) - .order("score DESC").page(@page).per(@number_of_articles) + .order(score: :desc).page(@page).per(@number_of_articles) end def latest_feed - published_articles_by_tag.order("published_at DESC") + published_articles_by_tag.order(published_at: :desc) .where("featured_number > ? AND score > ?", 1_449_999_999, -20) .page(@page).per(@number_of_articles) end @@ -238,7 +238,7 @@ module Articles def globally_hot_articles(user_signed_in) hot_stories = published_articles_by_tag .where("score > ? OR featured = ?", 7, true) - .order("hotness_score DESC") + .order(hotness_score: :desc) featured_story = hot_stories.where.not(main_image: nil).first if user_signed_in hot_story_count = hot_stories.count @@ -248,7 +248,7 @@ module Articles hot_stories = hot_stories.offset(offset) new_stories = Article.published .where("score > ?", -15) - .limited_column_select.includes(top_comments: :user).order("published_at DESC").limit(rand(15..80)) + .limited_column_select.includes(top_comments: :user).order(published_at: :desc).limit(rand(15..80)) hot_stories = hot_stories.to_a + new_stories.to_a end [featured_story, hot_stories.to_a] diff --git a/app/services/notifications/new_follower/send.rb b/app/services/notifications/new_follower/send.rb index b73e3448c..2eecc91a5 100644 --- a/app/services/notifications/new_follower/send.rb +++ b/app/services/notifications/new_follower/send.rb @@ -25,7 +25,7 @@ module Notifications def call recent_follows = Follow.where(followable_type: followable_type, followable_id: followable_id) - .where("created_at > ?", 24.hours.ago).order("created_at DESC") + .where("created_at > ?", 24.hours.ago).order(created_at: :desc) notification_params = { action: "Follow" } case followable_type diff --git a/app/services/notifications/reactions/send.rb b/app/services/notifications/reactions/send.rb index dbfb9d060..0b849641c 100644 --- a/app/services/notifications/reactions/send.rb +++ b/app/services/notifications/reactions/send.rb @@ -26,7 +26,7 @@ module Notifications reactable_type: reaction.reactable_type) .where.not(reactions: { user_id: reaction.reactable_user_id }) .preload(:reactable).includes(:user).where.not(users: { id: nil }) - .order("reactions.created_at DESC") + .order("reactions.created_at" => :desc) aggregated_reaction_siblings = reaction_siblings.map do |reaction| { category: reaction.category, created_at: reaction.created_at, user: user_data(reaction.user) } diff --git a/app/services/suggester/users/recent.rb b/app/services/suggester/users/recent.rb index 11f5a11b4..fc43ed153 100644 --- a/app/services/suggester/users/recent.rb +++ b/app/services/suggester/users/recent.rb @@ -34,7 +34,7 @@ module Suggester relation = User.where(id: tagged_article_user_ids(num_weeks)) relation = relation.select(attributes_to_select) if attributes_to_select - relation.order("updated_at DESC").limit(80).to_a + relation.order(updated_at: :desc).limit(80).to_a end def recent_top_producers @@ -44,14 +44,14 @@ module Suggester ) relation = relation.select(attributes_to_select) if attributes_to_select - relation.order("updated_at DESC").limit(50).to_a + relation.order(updated_at: :desc).limit(50).to_a end def recent_commenters(num_comments = 2, limit = 8) relation = User.where("comments_count > ?", num_comments) relation = relation.select(attributes_to_select) if attributes_to_select - relation.order("updated_at DESC").limit(limit).to_a + relation.order(updated_at: :desc).limit(limit).to_a end def established_user_article_count diff --git a/app/services/suggester/users/sidebar.rb b/app/services/suggester/users/sidebar.rb index 687bf9d6b..72efdb2dd 100644 --- a/app/services/suggester/users/sidebar.rb +++ b/app/services/suggester/users/sidebar.rb @@ -32,7 +32,7 @@ module Suggester end def reputable_user_ids - User.where(id: active_authors_for_given_tags).order("reputation_modifier DESC").limit(20).pluck(:id) + User.where(id: active_authors_for_given_tags).order(reputation_modifier: :desc).limit(20).pluck(:id) end def random_user_ids diff --git a/app/views/articles/_badges_area.html.erb b/app/views/articles/_badges_area.html.erb index 4718e3df4..81ace4553 100644 --- a/app/views/articles/_badges_area.html.erb +++ b/app/views/articles/_badges_area.html.erb @@ -40,7 +40,7 @@
- <% @user.badge_achievements.order("id DESC").includes(:badge).each do |achievement| %> + <% @user.badge_achievements.order(id: :desc).includes(:badge).each do |achievement| %>
- <% @listings.order("bumped_at DESC").limit(5).each do |listing| %> + <% @listings.order(bumped_at: :desc).limit(5).each do |listing| %>
<%= listing.title %>
diff --git a/app/views/articles/_sidebar_nav.html.erb b/app/views/articles/_sidebar_nav.html.erb index 78ca7b79f..98c27991e 100644 --- a/app/views/articles/_sidebar_nav.html.erb +++ b/app/views/articles/_sidebar_nav.html.erb @@ -99,7 +99,7 @@ DESIGN YOUR EXPERIENCE <% end %> - <% Tag.where(supported: true).order("hotness_score DESC").limit(30).pluck(:id, :name).each do |tag_array| %> + <% Tag.where(supported: true).order(hotness_score: :desc).limit(30).pluck(:id, :name).each do |tag_array| %>