order by id instead of created_at
id is indexed while created_at is not
This commit is contained in:
@@ -4,7 +4,7 @@ class BlogpostsController < ApplicationController
|
|||||||
before_filter :auth, except: [:index, :show]
|
before_filter :auth, except: [:index, :show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@posts = Blogpost.order("created_at desc").page(params[:page]).per(10)
|
@posts = Blogpost.order(id: :desc).page(params[:page]).per(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class ForumthreadsController < ApplicationController
|
|||||||
end
|
end
|
||||||
def show
|
def show
|
||||||
if params[:reverse] == "true"
|
if params[:reverse] == "true"
|
||||||
@replies = @thread.replies.order(created_at: :desc).page(params[:page])
|
@replies = @thread.replies.order(id: :desc).page(params[:page])
|
||||||
else
|
else
|
||||||
@replies = @thread.replies.order(:created_at).page(params[:page])
|
@replies = @thread.replies.order(:id).page(params[:page])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class Forumthread < ActiveRecord::Base
|
|||||||
if order_phrase.present?
|
if order_phrase.present?
|
||||||
threads = threads.order("GREATEST(relevance, reply_rel) DESC")
|
threads = threads.order("GREATEST(relevance, reply_rel) DESC")
|
||||||
else
|
else
|
||||||
threads = threads.order("sticky desc", "threadreplies.created_at DESC", "forumthreads.created_at DESC")
|
threads = threads.order("sticky DESC", "threadreplies.id DESC", "forumthreads.id DESC")
|
||||||
end
|
end
|
||||||
threads
|
threads
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<%= link_to f.name, f, id: "forum-#{f.id}"%>
|
<%= link_to f.name, f, id: "forum-#{f.id}"%>
|
||||||
<div class="item-info">
|
<div class="item-info">
|
||||||
<% if last_thread = f.threads.last %>
|
<% if last_thread = f.threads.last %>
|
||||||
<% last_reply = Threadreply.where(forumthread: f.threads).order(:created_at).last %>
|
<% last_reply = Threadreply.where(forumthread: f.threads).order(:id).last %>
|
||||||
<% if last_reply && last_reply.created_at > last_thread.created_at %>
|
<% if last_reply && last_reply.created_at > last_thread.created_at %>
|
||||||
<% if last_reply.thread.can_read?(current_user) %>
|
<% if last_reply.thread.can_read?(current_user) %>
|
||||||
<%= last_reply.author.name %>
|
<%= last_reply.author.name %>
|
||||||
|
|||||||
Reference in New Issue
Block a user