性能优化
This commit is contained in:
parent
0391503257
commit
6ece9c0463
|
@ -58,27 +58,26 @@ class IssuesController < ApplicationController
|
|||
include ApplicationHelper
|
||||
|
||||
def index
|
||||
# 为了性能所有用了两种模式,issue的@query查询所有的没有优势
|
||||
# 但是对过滤条件很有有时
|
||||
if params[:set_filter] != "1"
|
||||
@project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'
|
||||
@issues_filter = Issue.where(:project_id => @project.id).order('updated_on desc')
|
||||
if User.current.member_of?(@project)
|
||||
@issues_filter = Issue.where(:project_id => @project.id).order('updated_on desc')
|
||||
else
|
||||
@issues_filter = Issue.where(:project_id => @project.id, :is_private => 0).order('updated_on desc')
|
||||
end
|
||||
open_and_close_num(@project)
|
||||
@issue_count = @issues_filter.count
|
||||
@limit = 10
|
||||
@is_remote = true
|
||||
@issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1
|
||||
@offset ||= @issue_pages.offset
|
||||
@issues = paginateHelper @issues_filter, @limit
|
||||
# if params[:set_filter]
|
||||
# @set_filter = params[:set_filter]
|
||||
# end
|
||||
# @issue_count_by_group = @query.issue_count_by_group
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html { render :template => 'issues/index', :layout => @project_base_tag }#by young
|
||||
format.api {Issue.load_visible_relations(@issues) if include_in_api_response?('relations')}
|
||||
# format.json { render :json => @issues.map { |issue| issue.to_json}} #:json => @issues.map { |issue| issue.to_json}
|
||||
# format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
||||
# format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
|
||||
# format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
|
||||
format.xls {filename = "#{@project.name.to_s}_#{l(:label_issue_list_xls)}.xls"
|
||||
send_data(issue_list_xls(@issues_filter), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
|
@ -88,20 +87,8 @@ class IssuesController < ApplicationController
|
|||
sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria)
|
||||
sort_update(@query.sortable_columns)
|
||||
@query.sort_criteria = sort_criteria.to_a
|
||||
|
||||
@project_base_tag = (params[:project_id] || @issue.project) ? 'base_projects':'base'
|
||||
|
||||
if @query.valid?
|
||||
# case params[:format]
|
||||
# when 'csv', 'pdf'
|
||||
# @limit = 10#Setting.issues_export_limit.to_i
|
||||
# when 'atom'
|
||||
# @limit = 10#Setting.feeds_limit.to_i
|
||||
# when 'xml', 'json'
|
||||
# @offset, @limit = api_offset_and_limit({:limit => 10})
|
||||
# else
|
||||
# @limit = 10#per_page_option
|
||||
# end
|
||||
@tracker_id = params[:tracker_id]
|
||||
@assign_to_id = params[:assigned_to_id]
|
||||
@author_id = params[:author_id]
|
||||
|
@ -111,9 +98,6 @@ class IssuesController < ApplicationController
|
|||
@fixed_version_id = params[:fixed_version_id]
|
||||
@issue_count = @query.issue_count
|
||||
@test = params[:test]
|
||||
# @issue_pages = Paginator.new @issue_count, @limit, params['page']
|
||||
# params[:page] = (params[:page] || 1).to_i + 1 #页码需要加1
|
||||
# @offset ||= @issue_pages.offset
|
||||
@project_sort = 'issues.updated_on desc'
|
||||
if params[:test] != "0"
|
||||
case @test
|
||||
|
@ -127,6 +111,7 @@ class IssuesController < ApplicationController
|
|||
@project_sort = 'issues.updated_on asc'
|
||||
end
|
||||
end
|
||||
open_and_close_num(@project)
|
||||
@issues_filter_assign_count = @query.issues.select{|issue| issue.assigned_to_id == User.current.id }.count
|
||||
@issues_filter_author_count = @query.issues.select{|issue| issue.author_id == User.current.id }.count
|
||||
@issues_filter = @query.issues(:order => @project_sort)
|
||||
|
@ -135,35 +120,17 @@ class IssuesController < ApplicationController
|
|||
@issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1
|
||||
@offset ||= @issue_pages.offset
|
||||
@issues = paginateHelper @issues_filter, @limit
|
||||
# if params[:set_filter]
|
||||
# @set_filter = params[:set_filter]
|
||||
# end
|
||||
# @issue_count_by_group = @query.issue_count_by_group
|
||||
if params[:export_issue_hidden] == "1"
|
||||
# index(:format=>'xls', :export_issue_hidden => 0)
|
||||
params[:export_issue_hidden] = "0"
|
||||
redirect_to project_issues_path(:project_id => @project, :format => 'xls')
|
||||
|
||||
# respond_to do |format|
|
||||
# format.xls {filename = "#{@project.name.to_s}_#{l(:label_issue_list_xls)}.xls"
|
||||
# send_data(issue_list_xls(@issues_filter), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||
# return
|
||||
# }
|
||||
# return
|
||||
# end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html { render :template => 'issues/index', :layout => @project_base_tag }#by young
|
||||
format.api {Issue.load_visible_relations(@issues) if include_in_api_response?('relations')}
|
||||
# format.json { render :json => @issues.map { |issue| issue.to_json}} #:json => @issues.map { |issue| issue.to_json}
|
||||
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
||||
format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
|
||||
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
|
||||
format.xls {filename = "#{@project.name.to_s}_#{l(:label_issue_list_xls)}.xls"
|
||||
send_data(issue_list_xls(@issues_filter), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html { render :template => 'issues/index', :layout => @project_base_tag }#by young
|
||||
format.api {Issue.load_visible_relations(@issues) if include_in_api_response?('relations')}
|
||||
# format.json { render :json => @issues.map { |issue| issue.to_json}} #:json => @issues.map { |issue| issue.to_json}
|
||||
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
|
||||
format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
|
||||
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
|
||||
format.xls {filename = "#{@project.name.to_s}_#{l(:label_issue_list_xls)}.xls"
|
||||
send_data(issue_list_xls(@issues_filter), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
||||
}
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
|
@ -174,12 +141,21 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
# 获取issue的开启统计数
|
||||
def open_and_close_num project
|
||||
if User.current.member_of?(project)
|
||||
@issue_open_count = Issue.where("project_id=#{project.id} and status_id in (1,2,3,4,6)").count
|
||||
@issue_close_count = Issue.where(:project_id => project.id, :status_id => 5 ).count
|
||||
else
|
||||
@issue_open_count = Issue.where("project_id=#{project.id} and status_id in (1,2,3,4,6) and is_private = 0").count
|
||||
@issue_close_count = Issue.where(:project_id => project.id, :status_id => 5, :is_private => 0).count
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
# 打开编辑内容
|
||||
@is_edit = true unless params[:edit].nil?
|
||||
|
|
|
@ -120,8 +120,8 @@
|
|||
<div class="issues_statistics fl">
|
||||
<ul>
|
||||
<li>所有<a class="issues_greycirbg_btn "><%= @project.project_score.issue_num %></a></li>
|
||||
<li>开启<a class="issues_greycirbg_btn "><%#= @issues_filter_assign_count %><%= @project.issues.where('status_id in (1,2,3,4,6)').visible.all.count %></a></li>
|
||||
<li>关闭<a class="issues_greycirbg_btn "><%#= @issues_filter_author_count %><%= @project.issues.where(:status_id => 5 ).visible.all.count %></a></li>
|
||||
<li>开启<a class="issues_greycirbg_btn "><%#= @issues_filter_assign_count %><%= @issue_open_count %></a></li>
|
||||
<li>关闭<a class="issues_greycirbg_btn "><%#= @issues_filter_author_count %><%= @issue_close_count %></a></li>
|
||||
</ul>
|
||||
</div><!--issues_statistics end-->
|
||||
<!--<input type="button" class="hw_btn_blue fr" value="导出EXCEL" onclick="remote_function_export('<%= @project.id %>')">-->
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//$("#issue_list").html("<%#= escape_javascript(render :partial => 'issues/list',:locals => {:issues => @issues, :query => @query,:issue_pages=>@issue_pages,:issue_count=>@issue_count})%>");
|
||||
$("#issue_assigned_count").html("<%= escape_javascript(render :partial => 'issues/issue_filter') %>");
|
||||
//$("#issue_assigned_count").html("<%#= escape_javascript(render :partial => 'issues/issue_filter') %>");
|
||||
$("#issue_filter_all").html("<%= escape_javascript(render :partial => 'issues/issue_filter_all') %>");
|
||||
$("#issue_author_count").html("<%= escape_javascript(render :partial => 'issues/issue_filter_author') %>");
|
||||
//$("#issue_author_count").html("<%#= escape_javascript(render :partial => 'issues/issue_filter_author') %>");
|
||||
$("#issue_list").html("<%= escape_javascript(render :partial => 'issues/all_list',:locals => {:issues => @issues, :query => @query, :issue_pages=> @issue_pages, :issue_count => @issue_count, :project=> @project})%>");
|
||||
$("#issue_list_pagination").html('<%= pagination_links_full @issue_pages, @issue_count, :issues => @issues, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>');
|
||||
|
||||
|
|
Loading…
Reference in New Issue