mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Select columns specifically needed for WP autocompletion
This allows to make more efficient database queries in the API and reduces overhead by too large JSON responses. Assuming we fix #68457, additional improvements in response time can be expected, because we do not need to perform a count for all matching work packages anymore (because we do not select "total").
This commit is contained in:
+2
@@ -63,6 +63,8 @@ export class OpAutocompleterService extends UntilDestroyedMixin {
|
||||
protected createParams(resource:TOpAutocompleterResource):{ [p:string]:string } {
|
||||
if (resource === 'work_packages') {
|
||||
return {
|
||||
// see op-autocompleter/op-autocompleter.component.html for required attributes
|
||||
select: 'elements/id,elements/subject,elements/author,elements/type,elements/project,elements/status',
|
||||
sortBy: '[["updatedAt","desc"]]',
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,6 +44,26 @@ module API
|
||||
condition: "projects.id = work_packages.project_id",
|
||||
select: ["projects.name project_name"] }
|
||||
|
||||
link :status,
|
||||
path: { api: :status, params: %w(id) },
|
||||
column: -> { :status_id },
|
||||
title: -> { "status_name" },
|
||||
join: {
|
||||
table: :statuses,
|
||||
condition: "statuses.id = work_packages.status_id",
|
||||
select: ["statuses.name status_name"]
|
||||
}
|
||||
|
||||
link :type,
|
||||
path: { api: :type, params: %w(id) },
|
||||
column: -> { :type_id },
|
||||
title: -> { "type_name" },
|
||||
join: {
|
||||
table: :types,
|
||||
condition: "types.id = work_packages.type_id",
|
||||
select: ["types.name type_name"]
|
||||
}
|
||||
|
||||
associated_user_link :author
|
||||
|
||||
associated_user_link :assignee,
|
||||
|
||||
@@ -48,11 +48,13 @@ RSpec.describe API::V3::WorkPackages::WorkPackageSqlRepresenter, "rendering" do
|
||||
let(:rendered_work_package) do
|
||||
create(:work_package,
|
||||
project:,
|
||||
type:,
|
||||
assigned_to: assignee,
|
||||
author:,
|
||||
responsible:)
|
||||
end
|
||||
let(:project) { create(:project, types: [create(:type, is_milestone:)]) }
|
||||
let(:project) { create(:project, types: [type]) }
|
||||
let(:type) { create(:type, is_milestone:) }
|
||||
let(:is_milestone) { false }
|
||||
let(:assignee) { nil }
|
||||
let(:author) { create(:user) }
|
||||
@@ -91,6 +93,14 @@ RSpec.describe API::V3::WorkPackages::WorkPackageSqlRepresenter, "rendering" do
|
||||
author: {
|
||||
href: api_v3_paths.user(author.id),
|
||||
title: author.name
|
||||
},
|
||||
status: {
|
||||
href: api_v3_paths.status(rendered_work_package.status.id),
|
||||
title: rendered_work_package.status.name
|
||||
},
|
||||
type: {
|
||||
href: api_v3_paths.type(type.id),
|
||||
title: type.name
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,6 +138,14 @@ RSpec.describe API::V3::WorkPackages::WorkPackageSqlRepresenter, "rendering" do
|
||||
author: {
|
||||
href: api_v3_paths.user(author.id),
|
||||
title: author.name
|
||||
},
|
||||
status: {
|
||||
href: api_v3_paths.status(rendered_work_package.status.id),
|
||||
title: rendered_work_package.status.name
|
||||
},
|
||||
type: {
|
||||
href: api_v3_paths.type(type.id),
|
||||
title: type.name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user