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

add eager loading to time entries api

ulfertsed32a4969ca3
diff --git a/modules/costs/lib/api/v3/time_entries/time_entries_api.rb b/modules/costs/lib/api/v3/time_entries/time_entries_api.rb
index fd00be14d2d..a437253e5c9 100644
--- a/modules/costs/lib/api/v3/time_entries/time_entries_api.rb
+++ b/modules/costs/lib/api/v3/time_entries/time_entries_api.rb
@@ -33,7 +33,9 @@ module API
helpers ::API::Utilities::UrlPropsParsingHelper
resources :time_entries do
- get &::API::V3::Utilities::Endpoints::Index.new(model: TimeEntry).mount
+ get &::API::V3::Utilities::Endpoints::Index.new(model: TimeEntry,
+ scope: -> { TimeEntry.includes(TimeEntryRepresenter.to_eager_load) })
+ .mount
post &::API::V3::Utilities::Endpoints::Create.new(model: TimeEntry).mount
mount ::API::V3::TimeEntries::CreateFormAPI
diff --git a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
index 37dd5d63ea9..cc3e64369b5 100644
--- a/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
+++ b/modules/costs/lib/api/v3/time_entries/time_entry_representer.rb
@@ -132,6 +132,11 @@ module API
'hours',
allow_nil: true)
end
+
+ self.to_eager_load = [:work_package,
+ :user,
+ :activity,
+ { project: :enabled_modules }]
end
end
end