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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
avoid sorting and order on counting
ulferts15b81403c7f0
diff --git a/app/models/queries/projects/orders/name_order.rb b/app/models/queries/projects/orders/name_order.rbindex 0a5a2932753..cf2e148712d 100644--- a/app/models/queries/projects/orders/name_order.rb+++ b/app/models/queries/projects/orders/name_order.rb@@ -35,6 +35,10 @@ class Queries::Projects::Orders::NameOrder < Queries::BaseOrder:nameend+ def scope+ super.select('projects.*', 'lower(projects.name)')+ end+def orderwith_raise_on_invalid domodel.order(Arel.sql("lower(projects.name)").send(direction))diff --git a/lib/api/decorators/unpaginated_collection.rb b/lib/api/decorators/unpaginated_collection.rbindex efaafade73e..0456487f5a4 100644--- a/lib/api/decorators/unpaginated_collection.rb+++ b/lib/api/decorators/unpaginated_collection.rb@@ -31,7 +31,18 @@ module APImodule Decoratorsclass UnpaginatedCollection < ::API::Decorators::Collectiondef initialize(models, self_link, current_user:)- super(models, models.count, self_link, current_user: current_user)+ super(models, model_count(models), self_link, current_user: current_user)+ end++ def model_count(models)+ if models.respond_to?(:except)+ # We do not want any order/selecting with counting+ # when it would result in an invalid SELECT COUNT(DISTINCT *, ).+ # As both, order and select should have no impact on the count result, we remove them.+ models.except(:select, :order)+ else+ models+ end.countendendend