Browse Source

Sort messages by ids to avoid the left join.

The query was really slow with PostgreSQL and a few thousands messages, and last_message_id column was storing the highest id anyway.

git-svn-id: http://svn.redmine.org/redmine/trunk@15582 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/3.4.0
Jean-Philippe Lang 8 years ago
parent
commit
1b10649783
1 changed files with 4 additions and 5 deletions
  1. 4
    5
      app/controllers/boards_controller.rb

+ 4
- 5
app/controllers/boards_controller.rb View File

@@ -37,15 +37,14 @@ class BoardsController < ApplicationController
respond_to do |format|
format.html {
sort_init 'updated_on', 'desc'
sort_update 'created_on' => "#{Message.table_name}.created_on",
sort_update 'created_on' => "#{Message.table_name}.id",
'replies' => "#{Message.table_name}.replies_count",
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
'updated_on' => "COALESCE(#{Message.table_name}.last_reply_id, #{Message.table_name}.id)"

@topic_count = @board.topics.count
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
@topics = @board.topics.
reorder("#{Message.table_name}.sticky DESC").
joins("LEFT OUTER JOIN #{Message.table_name} last_replies_messages ON last_replies_messages.id = #{Message.table_name}.last_reply_id").
reorder(:sticky => :desc).
limit(@topic_pages.per_page).
offset(@topic_pages.offset).
order(sort_clause).
@@ -56,7 +55,7 @@ class BoardsController < ApplicationController
}
format.atom {
@messages = @board.messages.
reorder('created_on DESC').
reorder(:id => :desc).
includes(:author, :board).
limit(Setting.feeds_limit.to_i).
to_a

Loading…
Cancel
Save