Permalink
Browse files

remove json cache & performance optimization

  • Loading branch information...
1 parent 76fc502 commit 946ce40276d8ebe50e38acce71573921e1408625 @liufengyun liufengyun committed Mar 15, 2012
Showing with 26 additions and 28 deletions.
  1. +4 −4 app/models/abstract_task.rb
  2. +4 −4 app/models/task_filter.rb
  3. +18 −20 app/views/tasks/index.json.erb
@@ -94,13 +94,13 @@ def self.all_accessed_by(user)
readonly(false).joins(
"join project_permissions on
project_permissions.project_id = tasks.project_id
- join users on
- project_permissions.user_id = users.id"
+ join users as project_permission_users on
+ project_permissions.user_id = project_permission_users.id"
).where(
- "users.id= ? and
+ "project_permission_users.id= ? and
(
project_permissions.can_see_unwatched = ? or
- users.id in
+ project_permission_users.id in
(select task_users.user_id from task_users where task_users.task_id=tasks.id)
)",
user.id,
@@ -45,7 +45,7 @@ def tasks(extra_conditions = nil)
# Returns an array of all tasks matching the conditions from this filter.
def tasks_for_jqgrid(parameters)
parameters= parse_jqgrid_params(parameters)
- tasks(parameters[:conditions]).includes(parameters[:include]).joins(parameters[:joins]).order(parameters[:order]).limit(parameters[:limit]).offset(parameters[:offset])
+ tasks(parameters[:conditions]).includes(:milestone, :customers, :owners, :users, :watchers, :task_property_values, :company).joins(parameters[:joins]).order(parameters[:order]).limit(parameters[:limit]).offset(parameters[:offset])
end
# Returns an array of all tasks matching the conditions from this filter.
@@ -411,14 +411,14 @@ def parse_jqgrid_params(jqgrid_params)
end
case jqgrid_params[:sidx]
when 'updated_at'
- tasks_params[:joins]= "LEFT OUTER JOIN (SELECT task_id, MAX(started_at) AS started_at FROM work_logs WHERE company_id = #{self.company_id} GROUP BY task_id) work_logs ON tasks.id = work_logs.task_id"
- tasks_params[:order]='work_logs.started_at'
+ tasks_params[:joins]= "LEFT OUTER JOIN (SELECT task_id, MAX(started_at) AS started_at FROM work_logs WHERE company_id = #{self.company_id} GROUP BY task_id) last_comment_work_logs ON tasks.id = last_comment_work_logs.task_id"
+ tasks_params[:order]='last_comment_work_logs.started_at'
when 'summary'
tasks_params[:order]='tasks.name'
when 'id'
tasks_params[:order]='tasks.id'
when 'due'
- tasks_params[:include]=[:milestone]
+ # milestones must be included
tasks_params[:order]='(case isnull(tasks.due_at) when 1 then milestones.due_at when 0 then tasks.due_at end)'
when 'assigned'
tasks_params[:order]='(select group_concat(distinct users.name) from task_users left outer join users on users.id = task_users.user_id where task_users.task_id=tasks.id group by tasks.id)'
@@ -1,5 +1,4 @@
{"tasks": {
-"records":"<%= @tasks.size %>",
"rows": [
<%
total_time = 0
@@ -17,31 +16,30 @@
%>
{
"read":<%= readFlag.to_json.html_safe %>,
+ "id":<%= task.task_num.to_json.html_safe %>,
- <% cache(["task_json", task]) do %>
- "id":<%= task.task_num.to_json.html_safe %>,
-
- <% task.company.properties.each do |prop| -%>
- <% prop_query = TaskPropertyValue.find_by_task_id_and_property_id(task.id, prop.id).property_value rescue "" -%>
- <% prop_value = prop_query == "" ? "<span id='position_#{prop.name.downcase}_9999'></span>": "<span id='position_#{prop.name.downcase}_#{prop_query.position_to_s}'>#{prop_query.to_html}</span>" rescue "" -%>
- <%= h(prop.name.downcase).to_json.html_safe %>:<%= prop_value.to_json.html_safe %>,
- <% end -%>
+ <% task.task_property_values.each do |task_prop_value| %>
+ <% prop = task_prop_value.property %>
+ <% prop_value = task_prop_value.property_value %>
+ <% json_value = prop_value ? "<span id='position_#{prop.name.downcase}_9999'></span>": "<span id='position_#{prop.name.downcase}_#{prop_value.position_to_s}'>#{prop_value.to_html}</span>" rescue "" -%>
+ <%= h(prop.name.downcase).to_json.html_safe %>:<%= json_value.to_json.html_safe %>,
+ <% end %>
- "summary":<%= h(task.name).to_json.html_safe %>,
- "client":<%= h(customer.name).to_json.html_safe %>,
- <% str = [ task.project.name ] -%>
- <% str << task.milestone.name.strip if task.milestone_id.to_i > 0 -%>
- "milestone":<%= h(str.join("/")).to_json.html_safe %>,
- "due":<%= due_in_words(task).to_json.html_safe %>,
- "time":<%= task.minutes_left.to_i.to_json.html_safe rescue "\"\"".html_safe %>,
- "assigned":<%= h(task.owners.map{ |u| u.name }.join(", ")).to_json.html_safe %>,
- "resolution":<%= task.status_type.to_json.html_safe %>,
- "updated_at":<%= last_comment_date(task) %>
- <% end -%>
+ "summary":<%= h(task.name).to_json.html_safe %>,
+ "client":<%= h(customer.name).to_json.html_safe %>,
+ <% str = [ task.project.name ] -%>
+ <% str << task.milestone.name.strip if task.milestone_id.to_i > 0 -%>
+ "milestone":<%= h(str.join("/")).to_json.html_safe %>,
+ "due":<%= due_in_words(task).to_json.html_safe %>,
+ "time":<%= task.minutes_left.to_i.to_json.html_safe rescue "\"\"".html_safe %>,
+ "assigned":<%= h(task.owners.map{ |u| u.name }.join(", ")).to_json.html_safe %>,
+ "resolution":<%= task.status_type.to_json.html_safe %>,
+ "updated_at":<%= last_comment_date(task) %>
}
<%= "," unless @tasks.size - 1 == idx %>
<% end -%>
],
+"records":"<%= @tasks.size %>",
"userdata":{"time":<%= total_time.to_json.html_safe %>}
}
}

0 comments on commit 946ce40

Please sign in to comment.