-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug/57305 sorting by custom field has strong impact on performance for the project list #16841
Open
toy
wants to merge
26
commits into
dev
Choose a base branch
from
bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9201af8
[#57305] Sorting by custom field has strong impact on performance for…
toy de75198
remove unused option `if` from work package property select
toy cfe36b6
using instance variables instead of writers for work package selects
toy 3f4abec
inline set_xxx! methods in CustomFieldSelect
toy 4fd686d
rename order_statements to order_statement swithcing it to return sin…
toy 19c4111
apply null handling to ordering projects by custom field
toy 059f844
rename CustomField#null_handling to order_null_handling
toy 38b0992
using joins for custom field ordering, grouping should be broken
toy ac45ea4
move deciding which custom field can be grouped by to order statements
toy 7d4668b
enable grouping by float, string and link too
toy 004ab35
remove replacing nil by false which doesn't seem to be needed
toy bfc466b
handle joins for groupping by custom field
toy 341be96
fix join statement for group by to return ids instead of positions
toy 6960db8
handle absent values in group by
toy ca87936
pass group_by_join_statement to WorkPackageSelect.scoped_column_sum
toy 74d1286
disambigute value in summable_select_statement
toy b482958
use receive_messages as rubocop suggests
toy b32f241
deduplicate queries using template
toy 5266817
ensure group_by_join_statement is nil when group_by_statement is nil
toy 47c97a0
order empty values before present values for all custom field formats
toy f754b0e
fix order of list custom field groups to be same as when ordering
toy 383c5f4
use MIN instead of ANY_VALUE, as latter is available only in PostgreS…
toy aa9f044
fix columns used in summing
toy af97ea2
use group_id instead of id to name the column used to group from summing
toy f8d9195
extract method to calm rubocop
toy 5bd80f6
add resulting join sqls from template in comment
toy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,21 +32,20 @@ def initialize(custom_field) | |
|
||
@cf = custom_field | ||
|
||
set_name! | ||
set_sortable! | ||
set_groupable! | ||
set_summable! | ||
end | ||
|
||
def groupable_custom_field?(custom_field) | ||
%w(list date bool int).include?(custom_field.field_format) | ||
@name = custom_field.column_name.to_sym | ||
@sortable = custom_field.order_statement | ||
@sortable_join = custom_field.order_join_statement | ||
@groupable = custom_field.group_by_statement | ||
@groupable_join = custom_field.group_by_join_statement | ||
@groupable_select = custom_field.group_by_select_statement | ||
@summable = summable_statement | ||
end | ||
|
||
def caption | ||
@cf.name | ||
end | ||
|
||
delegate :null_handling, to: :custom_field | ||
def null_handling(...) = custom_field.order_null_handling(...) | ||
|
||
def custom_field | ||
@cf | ||
|
@@ -68,32 +67,6 @@ def self.instances(context = nil) | |
|
||
private | ||
|
||
def set_name! | ||
self.name = custom_field.column_name.to_sym | ||
end | ||
|
||
def set_sortable! | ||
self.sortable = custom_field.order_statements || false | ||
end | ||
|
||
def set_groupable! | ||
self.groupable = custom_field.group_by_statement if groupable_custom_field?(custom_field) | ||
self.groupable ||= false | ||
end | ||
|
||
def set_summable! | ||
self.summable = if %w(float int).include?(custom_field.field_format) | ||
select = summable_select_statement | ||
|
||
->(query, grouped) { | ||
Queries::WorkPackages::Selects::WorkPackageSelect | ||
.scoped_column_sum(summable_scope(query), select, grouped && query.group_by_statement) | ||
} | ||
else | ||
false | ||
end | ||
end | ||
|
||
def summable_scope(query) | ||
WorkPackage | ||
.where(id: query.results.work_packages) | ||
|
@@ -105,9 +78,22 @@ def summable_scope(query) | |
|
||
def summable_select_statement | ||
if custom_field.field_format == "int" | ||
"COALESCE(SUM(value::BIGINT)::BIGINT, 0) #{name}" | ||
"COALESCE(SUM(#{CustomValue.quoted_table_name}.value::BIGINT)::BIGINT, 0) #{name}" | ||
else | ||
"COALESCE(ROUND(SUM(#{CustomValue.quoted_table_name}.value::NUMERIC), 2)::FLOAT, 0.0) #{name}" | ||
end | ||
end | ||
|
||
def summable_statement | ||
if %w[float int].include?(custom_field.field_format) | ||
select = summable_select_statement | ||
|
||
->(query, grouped) { | ||
Queries::WorkPackages::Selects::WorkPackageSelect | ||
.scoped_column_sum(summable_scope(query), select, grouped:, query:) | ||
} | ||
else | ||
"COALESCE(ROUND(SUM(value::NUMERIC), 2)::FLOAT, 0.0) #{name}" | ||
false | ||
end | ||
end | ||
Comment on lines
+87
to
98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Diff may make it confusing, this is extracted from |
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo 'thejoin' -> 'the join'