Skip to content
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

Conversation

toy
Copy link
Contributor

@toy toy commented Sep 27, 2024

Ticket

OP#57305 + OP#57554

What are you trying to accomplish?

Screenshots

What approach did you choose and why?

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch 4 times, most recently from f7fbb59 to 40034e9 Compare October 4, 2024 12:49
@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch from 33ea0df to 29dac54 Compare October 4, 2024 13:14
@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch 4 times, most recently from 74aaecc to 73daf9f Compare October 10, 2024 18:07
Comment on lines +86 to 98
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diff may make it confusing, this is extracted from set_summable!

@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch 7 times, most recently from 172eb20 to 3dcfa9c Compare October 16, 2024 12:38
@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch from 89a556f to 5bd80f6 Compare October 18, 2024 17:24
@toy toy marked this pull request as ready for review October 18, 2024 17:26
Copy link
Contributor

@ulferts ulferts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good functionality and also performance wise, in the tests I have conducted. It is now possible to group by way more fields which when looking at community is nice.

There are some issues with the added grouping options, though. Of those, the first is but a display issue. But the second one leads to entries being sorted into the wrong group.

Grouping by integer cf

image

Here, the grouping happens with an integer cf. The groups however are presented as floats.

Grouping by link cf

image

The backend correctly returns just one item in the group. The frontend still places more entries into the group.

app/models/custom_field/order_statements.rb Outdated Show resolved Hide resolved
@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch from 5bd80f6 to e4acf8c Compare October 30, 2024 13:10
@toy
Copy link
Contributor Author

toy commented Oct 30, 2024

@ulferts I wasn't able to reproduce the problem with grouping, we should look at it together

@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch from e4acf8c to d103deb Compare November 1, 2024 17:37
@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch 2 times, most recently from c45ae94 to 804986d Compare November 11, 2024 18:17
@toy
Copy link
Contributor Author

toy commented Nov 11, 2024

Grouping by link is fixed by 804986d, the issue was already there, but it was not possible to group by link custom field. Similar problem exists for grouping by bool custom fields, as absence of value will lead to nil used for grouping/ordering, but default value (which can only be true or false) used for work package custom field value, so currently there will be odd groups or adding to wrong group, the issue exists on dev.
Very confusing result is on the following screenshot, where only work packages with ids 40 and 5 have value set for boolean custom field, so only first 3 groups are correct (false, true and -), following groups are created because custom field value is available for type TASK, so defaults to false, but not available for other types, so has null value, and as frontend expects groups to be in order, it creates a group every time next row group value is different from one for current row. But the false group must be in the api response, as otherwise algorithm will not be be able to match it with row value and create it, so error doesn't show up, or at least that bad.

@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch 2 times, most recently from 6f38bdc to 690b342 Compare November 13, 2024 13:59
@toy toy force-pushed the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch from 690b342 to dc28e44 Compare November 13, 2024 14:20
@toy
Copy link
Contributor Author

toy commented Nov 13, 2024

Last commit dc28e44 is also extracted as #17201

@toy toy requested a review from ulferts November 13, 2024 16:54
Copy link
Contributor

@ulferts ulferts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ulferts ulferts merged commit 5a003d3 into dev Nov 15, 2024
13 checks passed
@ulferts ulferts deleted the bug/57305-sorting-by-custom-field-has-strong-impact-on-performance-for-the-project-list branch November 15, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants