Modify timeout and make some queries more efficient (#593)
* Modify timeout and make some queries more efficient * Only query podcasts if user signed in * Remove unnecessary columns selected in boosted query etc.
This commit is contained in:
parent
88dfc9b83d
commit
e4bb8d7823
6 changed files with 29 additions and 14 deletions
|
|
@ -114,10 +114,7 @@ class StoriesController < ApplicationController
|
|||
@featured_story = @stories.where.not(main_image: nil).first&.decorate || Article.new
|
||||
end
|
||||
@stories = @stories.decorate
|
||||
@podcast_episodes = PodcastEpisode.
|
||||
includes(:podcast).
|
||||
order("published_at desc").
|
||||
select(:slug, :title, :podcast_id).limit(5)
|
||||
assign_podcasts
|
||||
@article_index = true
|
||||
@sidebar_ad = DisplayAd.where(approved: true, published: true, placement_area: "sidebar").first
|
||||
set_surrogate_key_header "articles", @stories.map(&:record_key)
|
||||
|
|
@ -265,6 +262,15 @@ class StoriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def assign_podcasts
|
||||
if user_signed_in?
|
||||
@podcast_episodes = PodcastEpisode.
|
||||
includes(:podcast).
|
||||
order("published_at desc").
|
||||
select(:slug, :title, :podcast_id).limit(5)
|
||||
end
|
||||
end
|
||||
|
||||
def article_finder(num_articles)
|
||||
Article.where(published: true).
|
||||
includes(:user).
|
||||
|
|
@ -287,6 +293,7 @@ class StoriesController < ApplicationController
|
|||
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).
|
||||
limited_column_select.
|
||||
where("featured_number > ?", 5.days.ago.to_i).
|
||||
order("RANDOM()").
|
||||
limit(8)
|
||||
|
|
@ -294,6 +301,7 @@ class StoriesController < ApplicationController
|
|||
more_articles = Article.tagged_with((["career","productivity","discuss","explainlikeimfive"]), any: true).
|
||||
includes(:user).
|
||||
where("comments_count > ?", comment_count_num).
|
||||
limited_column_select.
|
||||
where(published: true).
|
||||
where.not(id: @article.id, user_id: @article.user_id).
|
||||
where("featured_number > ?", 5.days.ago.to_i).
|
||||
|
|
@ -303,6 +311,7 @@ class StoriesController < ApplicationController
|
|||
|
||||
@user_stickies = (@organization || @user).articles.
|
||||
where(published: true).
|
||||
limited_column_select.
|
||||
tagged_with(article_tags, any: true).
|
||||
where.not(id: @article.id).order("published_at DESC").
|
||||
limit(2)
|
||||
|
|
|
|||
|
|
@ -66,9 +66,10 @@ class Article < ApplicationRecord
|
|||
scope :limited_column_select, -> {
|
||||
select(:path, :title, :id,
|
||||
:comments_count, :positive_reactions_count, :cached_tag_list,
|
||||
:main_image, :main_image_background_hex_color, :updated_at,
|
||||
:main_image, :main_image_background_hex_color, :updated_at, :slug,
|
||||
:video, :user_id, :organization_id, :video_source_url, :video_code,
|
||||
:video_thumbnail_url, :video_closed_caption_track_url, :published_at, :crossposted_at)
|
||||
:video_thumbnail_url, :video_closed_caption_track_url,
|
||||
:published_at, :crossposted_at, :boost_states, :description)
|
||||
}
|
||||
|
||||
scope :limited_columns_internal_select, -> {
|
||||
|
|
|
|||
|
|
@ -113,6 +113,8 @@ class Comment < ApplicationRecord
|
|||
|
||||
def self.rooted_on(commentable_id, commentable_type)
|
||||
includes(:user, :commentable).
|
||||
select(:id, :user_id, :commentable_type, :commentable_id,
|
||||
:deleted, :created_at, :processed_html, :ancestry).
|
||||
where(commentable_id: commentable_id,
|
||||
ancestry: nil,
|
||||
commentable_type: commentable_type)
|
||||
|
|
|
|||
|
|
@ -20,9 +20,11 @@ module Suggester
|
|||
|
||||
def qualifying_articles(tag_names)
|
||||
tag_name = tag_names.sample
|
||||
Rails.cache.fetch("classic-article-for-tag-#{tag_name}}", expires_in: 45.minutes) do
|
||||
Rails.cache.
|
||||
fetch("classic-article-for-tag-#{tag_name}}", expires_in: 90.minutes) do
|
||||
Article.tagged_with(tag_name).
|
||||
includes(:user).
|
||||
limited_column_select.
|
||||
where(published: true, featured: true).
|
||||
where("positive_reactions_count > ?", MIN_REACTION_COUNT).
|
||||
where("published_at > ?", 10.months.ago).
|
||||
|
|
|
|||
|
|
@ -8,12 +8,13 @@ module Suggester
|
|||
end
|
||||
|
||||
def suggest
|
||||
Article.where(published: true, featured: true).
|
||||
includes(:user).
|
||||
where("positive_reactions_count > ?", MIN_HQ_REACTION_COUNT).
|
||||
order("RANDOM()").
|
||||
where.not(id: @not_ids).
|
||||
first
|
||||
Article.where(published: true, featured: true).
|
||||
includes(:user).
|
||||
where("positive_reactions_count > ?", MIN_HQ_REACTION_COUNT).
|
||||
order("RANDOM()").
|
||||
limited_column_select.
|
||||
where.not(id: @not_ids).
|
||||
first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Rails.application.config.middleware.insert_before Rack::Runtime, Rack::Timeout, wait_timeout: 5, service_timeout: ENV["SERVICE_TIMEOUT"].to_i # seconds
|
||||
# Rails.application.config.middleware.insert_before Rack::Runtime, Rack::Timeout, wait_timeout: 5, service_timeout: ENV["SERVICE_TIMEOUT"].to_i # seconds
|
||||
|
||||
Rack::Timeout.unregister_state_change_observer(:logger) if Rails.env.development?
|
||||
Rack::Timeout::Logger.disable
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue