Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

switch order to avoid CTE being included unnecessarily in subselects

Jens Ulferts96c2e7df046d
diff --git a/app/models/work_packages/scopes/include_spent_time.rb b/app/models/work_packages/scopes/include_spent_time.rb
index b3b6fbc1a9e..aed520aecd4 100644
--- a/app/models/work_packages/scopes/include_spent_time.rb
+++ b/app/models/work_packages/scopes/include_spent_time.rb
@@ -31,8 +31,8 @@ module WorkPackages::Scopes::IncludeSpentTime
class_methods do
def include_spent_time(user, work_package = nil)
- scope = with(visible_time_entries_cte.name => allowed_to_view_time_entries(user))
- .left_join_self_and_descendants(user, work_package)
+ scope = left_join_self_and_descendants(user, work_package)
+ .with(visible_time_entries_cte.name => allowed_to_view_time_entries(user))
.joins(join_visible_time_entries.join_sources)
.group(:id)
.select("SUM(#{visible_time_entries_cte.name}.hours) AS hours")