Skip to content

Commit f9db2e5

Browse files
Improved Statistic helper sql query
1 parent 5dffc21 commit f9db2e5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/helpers/statistic_helper.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def get_day_statistic
2929
SUM(ext_spend_hours.hours) AS ext_spend_hours,
3030
SUM(int_spend_hours.hours) AS int_spend_hours
3131
FROM users
32-
LEFT JOIN (SELECT *
32+
LEFT JOIN (SELECT
33+
time_entries.user_id as user_id,
34+
SUM(time_entries.hours) as hours
3335
FROM time_entries
3436
WHERE spent_on = CURDATE()
3537
AND time_entries.project_id IN (SELECT custom_values.customized_id
@@ -39,9 +41,12 @@ def get_day_statistic
3941
WHERE custom_fields.type = 'ProjectCustomField' AND
4042
custom_fields.name = #{ActiveRecord::Base.sanitize(internal_project_attr)}) AND
4143
custom_values.value != '1')
44+
GROUP BY time_entries.user_id
4245
) AS ext_spend_hours
4346
ON users.id = ext_spend_hours.user_id
44-
LEFT JOIN (SELECT *
47+
LEFT JOIN (SELECT
48+
time_entries.user_id as user_id,
49+
SUM(time_entries.hours) as hours
4550
FROM time_entries
4651
WHERE spent_on = CURDATE()
4752
AND time_entries.project_id IN (SELECT custom_values.customized_id
@@ -51,6 +56,7 @@ def get_day_statistic
5156
WHERE custom_fields.type = 'ProjectCustomField' AND
5257
custom_fields.name = #{ActiveRecord::Base.sanitize(internal_project_attr)}) AND
5358
custom_values.value = '1')
59+
GROUP BY time_entries.user_id
5460
) AS int_spend_hours
5561
ON users.id = int_spend_hours.user_id
5662
WHERE users.id IN #{str_arr}

0 commit comments

Comments
 (0)