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

Fixes Performance/CompareWithBlock offenses

Klaus Zanders58a4775f196e
diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb
index 36d63627f47..e228d150970 100644
--- a/app/controllers/repositories_controller.rb
+++ b/app/controllers/repositories_controller.rb
@@ -391,9 +391,7 @@ class RepositoriesController < ApplicationController
def graph_commits_per_author(repository)
commits_by_author = Changeset.where(['repository_id = ?', repository.id]).group(:committer).size
- commits_by_author.to_a.sort! do |x, y|
- x.last <=> y.last
- end
+ commits_by_author.to_a.sort_by!(&:last)
changes_by_author = Change.includes(:changeset)
.where(["#{Changeset.table_name}.repository_id = ?", repository.id])
diff --git a/lib/open_project/scm/adapters/subversion.rb b/lib/open_project/scm/adapters/subversion.rb
index 486e18a7e5c..065eace0bfe 100644
--- a/lib/open_project/scm/adapters/subversion.rb
+++ b/lib/open_project/scm/adapters/subversion.rb
@@ -166,7 +166,7 @@ module OpenProject
revisions = Revisions.new
fetch_revision_entries(identifier_from, identifier_to, options, path) do |logentry|
paths = logentry.xpath('paths/path').map { |entry| build_path(entry) }
- paths.sort! { |x, y| x[:path] <=> y[:path] }
+ paths.sort_by! { |a| a[:path] }
r = extract_revision(logentry)
r.paths = paths
diff --git a/lib/tasks/copyright_authors.rake b/lib/tasks/copyright_authors.rake
index d7f7792c106..3ff0163eb7a 100644
--- a/lib/tasks/copyright_authors.rake
+++ b/lib/tasks/copyright_authors.rake
@@ -57,7 +57,7 @@ namespace :copyright do
authors.each do |a|
first, last = contributions.select { |c| c.author == a }
- .minmax { |a, b| a.date <=> b.date }
+ .minmax_by(&:date)
contribution_periods << CONTRIBUTION_PERIOD.new(a, first.date.year, last.date.year)
end
diff --git a/modules/reporting/app/models/cost_query.rb b/modules/reporting/app/models/cost_query.rb
index a5293d4acdb..c9a8089ed92 100644
--- a/modules/reporting/app/models/cost_query.rb
+++ b/modules/reporting/app/models/cost_query.rb
@@ -87,7 +87,7 @@ class CostQuery < ApplicationRecord
def serialize
# have to take the reverse group_bys to retain the original order when deserializing
- self.serialized = { filters: (filters.map(&:serialize).reject(&:nil?).sort { |a, b| a.first <=> b.first }),
+ self.serialized = { filters: (filters.map(&:serialize).reject(&:nil?).sort_by(&:first)),
group_bys: group_bys.map(&:serialize).reject(&:nil?).reverse }
end