Skip to content
Snippets Groups Projects
Commit fd72f503 authored by ArtOfCode-'s avatar ArtOfCode-
Browse files

More efficient hot questions selection

parent 67d0cd76
Branches
Tags
No related merge requests found
......@@ -105,9 +105,9 @@ class ApplicationController < ActionController::Base
end
def pull_hot_questions
@hot_questions = Rails.cache.fetch('hot_questions', expires_in: 30.minutes) do
Post.undeleted.where(updated_at: (Rails.env.development? ? 365 : 1).days.ago..Time.now)
.where(parent_id: nil).includes(:category)
@hot_questions = Rails.cache.fetch('hot_questions', expires_in: 4.hours) do
Post.undeleted.where(updated_at: (Rails.env.development? ? 365 : 7).days.ago..Time.now)
.where(post_type_id: Question.post_type_id).includes(:category)
.order('score DESC').limit(SiteSetting['HotQuestionsCount'])
end
end
......
......@@ -12,7 +12,7 @@
<% end %>
<% end %>
<% if Rails.env.development? || @hot_questions.size > 0 %>
<% if Rails.env.development? || @hot_questions.to_a.size > 0 %>
<div class="widget has-margin-4">
<h4 class="widget--header has-margin-0">Hot Posts</h4>
<% @hot_questions.each do |hq| %>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment