##// END OF EJS Templates
Sort messages by ids to avoid the left join....
Jean-Philippe Lang -
r15200:1b10649783e2
parent child
Show More
@@ -1,120 +1,119
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2016 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class BoardsController < ApplicationController
19 19 default_search_scope :messages
20 20 before_filter :find_project_by_project_id, :find_board_if_available, :authorize
21 21 accept_rss_auth :index, :show
22 22
23 23 helper :sort
24 24 include SortHelper
25 25 helper :watchers
26 26
27 27 def index
28 28 @boards = @project.boards.preload(:project, :last_message => :author).to_a
29 29 # show the board if there is only one
30 30 if @boards.size == 1
31 31 @board = @boards.first
32 32 show
33 33 end
34 34 end
35 35
36 36 def show
37 37 respond_to do |format|
38 38 format.html {
39 39 sort_init 'updated_on', 'desc'
40 sort_update 'created_on' => "#{Message.table_name}.created_on",
40 sort_update 'created_on' => "#{Message.table_name}.id",
41 41 'replies' => "#{Message.table_name}.replies_count",
42 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
42 'updated_on' => "COALESCE(#{Message.table_name}.last_reply_id, #{Message.table_name}.id)"
43 43
44 44 @topic_count = @board.topics.count
45 45 @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
46 46 @topics = @board.topics.
47 reorder("#{Message.table_name}.sticky DESC").
48 joins("LEFT OUTER JOIN #{Message.table_name} last_replies_messages ON last_replies_messages.id = #{Message.table_name}.last_reply_id").
47 reorder(:sticky => :desc).
49 48 limit(@topic_pages.per_page).
50 49 offset(@topic_pages.offset).
51 50 order(sort_clause).
52 51 preload(:author, {:last_reply => :author}).
53 52 to_a
54 53 @message = Message.new(:board => @board)
55 54 render :action => 'show', :layout => !request.xhr?
56 55 }
57 56 format.atom {
58 57 @messages = @board.messages.
59 reorder('created_on DESC').
58 reorder(:id => :desc).
60 59 includes(:author, :board).
61 60 limit(Setting.feeds_limit.to_i).
62 61 to_a
63 62 render_feed(@messages, :title => "#{@project}: #{@board}")
64 63 }
65 64 end
66 65 end
67 66
68 67 def new
69 68 @board = @project.boards.build
70 69 @board.safe_attributes = params[:board]
71 70 end
72 71
73 72 def create
74 73 @board = @project.boards.build
75 74 @board.safe_attributes = params[:board]
76 75 if @board.save
77 76 flash[:notice] = l(:notice_successful_create)
78 77 redirect_to_settings_in_projects
79 78 else
80 79 render :action => 'new'
81 80 end
82 81 end
83 82
84 83 def edit
85 84 end
86 85
87 86 def update
88 87 @board.safe_attributes = params[:board]
89 88 if @board.save
90 89 respond_to do |format|
91 90 format.html {
92 91 flash[:notice] = l(:notice_successful_update)
93 92 redirect_to_settings_in_projects
94 93 }
95 94 format.js { render :nothing => true }
96 95 end
97 96 else
98 97 respond_to do |format|
99 98 format.html { render :action => 'edit' }
100 99 format.js { render :nothing => true, :status => 422 }
101 100 end
102 101 end
103 102 end
104 103
105 104 def destroy
106 105 @board.destroy
107 106 redirect_to_settings_in_projects
108 107 end
109 108
110 109 private
111 110 def redirect_to_settings_in_projects
112 111 redirect_to settings_project_path(@project, :tab => 'boards')
113 112 end
114 113
115 114 def find_board_if_available
116 115 @board = @project.boards.find(params[:id]) if params[:id]
117 116 rescue ActiveRecord::RecordNotFound
118 117 render_404
119 118 end
120 119 end
General Comments 0
You need to be logged in to leave comments. Login now