summaryrefslogtreecommitdiffstats
path: root/app/controllers/boards_controller.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-06-20 19:03:53 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-06-20 19:03:53 +0000
commit1b10649783e2884fde72501bf86a78b68f24ea57 (patch)
treeaebed9b6ecd0f7e7fa44799ac680eac11a2352fd /app/controllers/boards_controller.rb
parent3f20ab690d08af503a06a55e93d605bd6a12a84c (diff)
downloadredmine-1b10649783e2884fde72501bf86a78b68f24ea57.tar.gz
redmine-1b10649783e2884fde72501bf86a78b68f24ea57.zip
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
Diffstat (limited to 'app/controllers/boards_controller.rb')
-rw-r--r--app/controllers/boards_controller.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb
index 9ab80f4f9..df2567fab 100644
--- a/app/controllers/boards_controller.rb
+++ b/app/controllers/boards_controller.rb
@@ -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