Commit 7295cc8e by Tấn Trần Thanh

delete redundant includes models

parent 950db87a
Pipeline #1611 failed with stages
in 0 seconds
...@@ -5,7 +5,7 @@ class WorkflowReportIssue < Issue ...@@ -5,7 +5,7 @@ class WorkflowReportIssue < Issue
has_many :workflow_report_custom_values, class_name: 'WorkflowReportCustomValue', foreign_key: 'customized_id' has_many :workflow_report_custom_values, class_name: 'WorkflowReportCustomValue', foreign_key: 'customized_id'
scope :raw_tasks_records, -> (year, month, project_ids) { scope :raw_tasks_records, -> (year, month, project_ids) {
includes(:project, :workflow_report_version, :workflow_report_custom_values, :time_entries, :status, project: :enabled_modules) includes(:time_entries, project: :enabled_modules)
.where.not(projects: { status: CLOSED_STATUS_PROJECT }, issues: { tracker_id: BUG_TRACKER_ID }) .where.not(projects: { status: CLOSED_STATUS_PROJECT }, issues: { tracker_id: BUG_TRACKER_ID })
.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 ?))',
......
...@@ -23,8 +23,9 @@ module WorkflowReport ...@@ -23,8 +23,9 @@ module WorkflowReport
return { workflow_report: [], error_links: [] } if raw_tasks.empty? return { workflow_report: [], error_links: [] } if raw_tasks.empty?
raw_tasks.group_by(&:root_id).each do |root_id, issues| raw_tasks.group_by(&:root_id).each do |root_id, issues|
issue_ids = issues.map(&:id) arr_issue = WorkflowReportIssue.where(root_id: root_id)
root_issue = WorkflowReportIssue.find(root_id) issue_ids = arr_issue.map(&:id)
root_issue = arr_issue.find(root_id)
journals = WorkflowReportJournal.find_journal_by_issue_ids(issue_ids).to_a journals = WorkflowReportJournal.find_journal_by_issue_ids(issue_ids).to_a
result[0] << root_id result[0] << root_id
...@@ -40,9 +41,9 @@ module WorkflowReport ...@@ -40,9 +41,9 @@ module WorkflowReport
issue_due_date = issue_due_dates.max_by { |due_date| due_date } issue_due_date = issue_due_dates.max_by { |due_date| due_date }
result[6].push(issue_due_date.present? ? issue_due_date&.strftime('%Y-%m-%d %H:%M:%S') : '') result[6].push(issue_due_date.present? ? issue_due_date&.strftime('%Y-%m-%d %H:%M:%S') : '')
result[7].push(root_issue.status&.name.present? ? root_issue.status&.name : '') result[7].push(root_issue.status&.name.present? ? root_issue.status&.name : '')
sum_estimated_hours = issues.map(&:estimated_hours).compact.sum sum_estimated_hours = arr_issue.map(&:estimated_hours).compact.sum
result[8] << sum_estimated_hours.round(2) result[8] << sum_estimated_hours.round(2)
actual_time = issues.map { |issue| issue.time_entries.sum(:hours) }.sum actual_time = TimeEntry.where(issue_id: issue_ids).sum(:hours)
if actual_time.present? if actual_time.present?
result[9] << actual_time.round(2) result[9] << actual_time.round(2)
result[10] << (actual_time - sum_estimated_hours).round(2) result[10] << (actual_time - sum_estimated_hours).round(2)
...@@ -61,7 +62,7 @@ module WorkflowReport ...@@ -61,7 +62,7 @@ module WorkflowReport
else else
(11..13).each { |i| result[i] << '' } (11..13).each { |i| result[i] << '' }
end end
issues.each do |issue| arr_issue.each do |issue|
if issue.tracker_id == USER_STORY_TRACKER_ID if issue.tracker_id == USER_STORY_TRACKER_ID
pr_links = issue.custom_values.find_by(custom_field_id: PR_FIELD_ID)&.value pr_links = issue.custom_values.find_by(custom_field_id: PR_FIELD_ID)&.value
jp_request = issue.custom_values.find_by(custom_field_id: JP_REQUEST_FIELD_ID)&.value jp_request = issue.custom_values.find_by(custom_field_id: JP_REQUEST_FIELD_ID)&.value
......
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