Rearrange some code to remove unnecessary queries (#787)

* Change harcoded memcache limit

* Rearrange some code to remove unnecessary queries
This commit is contained in:
Ben Halpern 2018-10-02 10:59:51 -04:00 committed by GitHub
parent d5341a9130
commit 97a8958a87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View file

@ -167,9 +167,7 @@ class StoriesController < ApplicationController
redirect_to_changed_username_profile
return
end
comment_count = params[:view] == "comments" ? 250 : 8
@comments = @user.comments.where(deleted: false).
order("created_at DESC").includes(:commentable).limit(comment_count)
assign_user_comments
@stories = ArticleDecorator.decorate_collection(@user.
articles.where(published: true).
limited_column_select.
@ -219,7 +217,6 @@ class StoriesController < ApplicationController
assign_second_and_third_user
not_found if permission_denied?
set_surrogate_key_header @article.record_key
@classic_article = Suggester::Articles::Classic.new(@article).get
unless user_signed_in?
response.headers["Surrogate-Control"] = "max-age=10000, stale-while-revalidate=30, stale-if-error=86400"
end
@ -260,6 +257,16 @@ class StoriesController < ApplicationController
@user = @article&.user || not_found # The org may have changed back to user and this does not handle that properly
end
def assign_user_comments
comment_count = params[:view] == "comments" ? 250 : 8
@comments = if @user.comments_count > 0
@user.comments.where(deleted: false).
order("created_at DESC").includes(:commentable).limit(comment_count)
else
[]
end
end
def assign_user_article
@user = User.find_by_username(params[:username].downcase)
return unless @user

View file

@ -207,6 +207,7 @@
<% end %>
</div>
<% cache("article-bottom-content-#{@article.cached_tag_list_array.sort}", :expires_in => 6.hours) do %>
<% @classic_article = Suggester::Articles::Classic.new(@article).get %>
<% if @classic_article %>
<%= render "additional_content_boxes/article_box",
article: @classic_article,
@ -232,12 +233,6 @@
<script async defer src="//platform.instagram.com/en_US/embeds.js"></script>
<% end %>
<% if @article.processed_html.include?("interactive-code-wrapper") && @article.user.username == "ben" %>
<%= render 'articles/klipse_script' %>
<% end %>
<% cache("article-show-scripts", expires_in: 6.hours) do %>
<script async>
<%= TweetTag.script.html_safe %>