Commit 5a425a8a by Tấn Trần Thanh

Merge branch 'feature/improve-performance-workflow-report' into 'hotfix/workflow-report-plugin'

Feature/improve performance workflow report

See merge request !12
parents 97f51e2f 950db87a
Pipeline #1610 failed with stages
in 0 seconds
...@@ -48,6 +48,7 @@ class WorkflowReportController < ApplicationController ...@@ -48,6 +48,7 @@ class WorkflowReportController < ApplicationController
result = Rails.cache.fetch("#{team}_#{params[:year]}_#{params[:month]}", expires_in: 1.hours) do result = Rails.cache.fetch("#{team}_#{params[:year]}_#{params[:month]}", expires_in: 1.hours) do
WorkflowReport.build_report(params[:year].to_i, params[:month].to_i, project_ids) WorkflowReport.build_report(params[:year].to_i, params[:month].to_i, project_ids)
end end
respond_to do |format| respond_to do |format|
format.js { render 'build_table', locals: { result: result[:workflow_report], error_links: result[:error_links], thead: TABLE_HEADER } } format.js { render 'build_table', locals: { result: result[:workflow_report], error_links: result[:error_links], thead: TABLE_HEADER } }
end end
......
class WorkflowReportCustomValue < CustomValue
belongs_to :workflow_report_issue, class_name: 'WorkflowReportCustomValue', foreign_key: 'custom_field_id'
end
class WorkflowReportIssue < Issue class WorkflowReportIssue < Issue
TESTCASE_FIELD_ID = 22 BUG_TRACKER_ID = 1
BUGS_FIELD_ID = 23 CLOSED_STATUS_PROJECT = 9
STG_BUGS_FIELD_ID = 27 belongs_to :workflow_report_version, class_name: 'Version', foreign_key: 'fixed_version_id'
PROD_BUGS_FIELD_ID = 28 has_many :workflow_report_custom_values, class_name: 'WorkflowReportCustomValue', foreign_key: 'customized_id'
PR_FIELD_ID = 18
JP_REQUEST_FIELD_ID = 16
scope :find_root_ids, ->(year, month, project_ids) { scope :raw_tasks_records, -> (year, month, project_ids) {
joins(:project, project: :enabled_modules) includes(:project, :workflow_report_version, :workflow_report_custom_values, :time_entries, :status, project: :enabled_modules)
.joins('LEFT OUTER JOIN time_entries ON issues.id = time_entries.issue_id') .where.not(projects: { status: CLOSED_STATUS_PROJECT }, issues: { tracker_id: BUG_TRACKER_ID })
.where.not(projects: { status: 9 })
.where(projects: { id: project_ids }, enabled_modules: { name: 'time_tracking' }) .where(projects: { id: project_ids }, enabled_modules: { name: 'time_tracking' })
.where(['((time_entries.spent_on IS NOT NULL AND time_entries.tyear = ? AND time_entries.tmonth = ?) OR (issues.closed_on BETWEEN ? AND ?))', .where(['((time_entries.spent_on IS NOT NULL AND time_entries.tyear = ? AND time_entries.tmonth = ?) OR (issues.closed_on BETWEEN ? AND ?))',
year, month, DateTime.new(year, month).beginning_of_day, DateTime.new(year, month, -1).end_of_day]) year, month, DateTime.new(year, month).beginning_of_day, DateTime.new(year, month, -1).end_of_day])
.distinct.pluck(:root_id)
}
scope :find_sum_hours_records, ->(root_ids) {
select(:root_id, 'sum(time_entries.hours) as hours', 'max(IFNULL(c1.value,-1)) as testcases', 'max(IFNULL(c2.value,-1)) as bugs', 'max(IFNULL(stg.value,-1)) as stg_bugs', 'max(IFNULL(prod.value,-1)) as prod_bugs')
.joins(:time_entries)
.joins("LEFT OUTER JOIN custom_values c1 ON c1.customized_id = issues.id and c1.custom_field_id=#{TESTCASE_FIELD_ID}")
.joins("LEFT OUTER JOIN custom_values c2 ON c2.customized_id = issues.id and c2.custom_field_id=#{BUGS_FIELD_ID}")
.joins("LEFT OUTER JOIN custom_values stg ON stg.customized_id = issues.id and stg.custom_field_id=#{STG_BUGS_FIELD_ID}")
.joins("LEFT OUTER JOIN custom_values prod ON prod.customized_id = issues.id and prod.custom_field_id=#{PROD_BUGS_FIELD_ID}")
.where(issues: { root_id: root_ids })
.where.not(issues: { tracker_id: 1 })
.group(:root_id)
}
scope :raw_tasks_records, ->(root_ids) {
select(:root_id, :id, :tracker_id, :subject, :due_date, :created_on, :closed_on, :estimated_hours, 'issue_statuses.name as status', 'versions.name as target_version', 'projects.name as project', 'pr.value as pr', 'jr.value as jp_request')
.joins(:project, :status)
.joins('LEFT JOIN versions ON issues.fixed_version_id = versions.id')
.joins("LEFT OUTER JOIN custom_values jr ON jr.customized_id = issues.id and jr.custom_field_id=#{JP_REQUEST_FIELD_ID}")
.joins("LEFT OUTER JOIN custom_values pr ON pr.customized_id = issues.id and pr.custom_field_id=#{PR_FIELD_ID}")
.where(issues: { root_id: root_ids })
.where.not(issues: { tracker_id: 1 })
.order(:root_id) .order(:root_id)
} }
end end
class WorkflowReportJournal < Journal class WorkflowReportJournal < Journal
scope :find_journal_by_issue_ids, ->(issue_ids) { scope :find_journal_by_issue_ids, -> (issue_ids) {
joins(:details) includes(:details)
.where(journals: { journalized_id: issue_ids }, journal_details: { prop_key: 'estimated_hours' }) .where(journals: { journalized_id: issue_ids }, journal_details: { prop_key: 'estimated_hours' })
.order(:journalized_id, :id) .order(:journalized_id, :id)
.pluck(:journalized_id, :old_value, :value, :created_on, :notes) .pluck(:journalized_id, :old_value, :value, :created_on, :notes)
......
class WorkflowReportVersion < Version
has_many :workflow_report_issues, foreign_key: 'fixed_version_id'
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment