Patch #26747

use find_by to replace where.first

Added by jwjw yy 10 months ago. Updated 9 months ago.

Status:Needs feedbackStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Code cleanup/refactoring
Target version:-

Description

sicne where.first will issue query with order by primary key which is actually unnecessary.

redmine/app/helpers/application_helper.rb:909:              u = User.visible.where(:id => oid, :type => 'User').first
redmine/app/helpers/application_helper.rb:941:                  if repository && (changeset = Changeset.visible.where("repository_id = ? AND scmid LIKE ?", repository.id, "#{name}%").first)
redmine/app/helpers/application_helper.rb:966:              if p = Project.visible.where("identifier = :s OR LOWER(name) = :s", :s => name.downcase).first
redmine/app/helpers/application_helper.rb:970:              u = User.visible.where(:login => name, :type => 'User').first
redmine/app/helpers/application_helper.rb:975:            u = User.visible.where(:login => name, :type => 'User').first
redmine/app/models/issue_query.rb:474:      root_id, lft, rgt = Issue.where(:id => value.first.to_i).pluck(:root_id, :lft, :rgt).first
redmine/app/models/issue_query.rb:490:      parent_id = Issue.where(:id => value.first.to_i).pluck(:parent_id).first
redmine/app/models/issue_query.rb:497:      root_id, lft, rgt = Issue.where(:id => value.first.to_i).pluck(:root_id, :lft, :rgt).first
redmine/app/models/wiki_content_version.rb:94:      where("wiki_content_id = ? AND version < ?", wiki_content_id, version).first
redmine/app/models/wiki_content_version.rb:102:      where("wiki_content_id = ? AND version > ?", wiki_content_id, version).first
redmine/app/models/principal.rb:128:    Principal.visible(user).where(:id => id).first == self
redmine/app/models/token.rb:115:    token = Token.where(:action => action, :value => key).first
redmine/app/models/user.rb:196:    user = where(:identity_url => url).first
redmine/app/models/user.rb:489:        user = where("LOWER(login) = ?", login.downcase).first
redmine/app/models/user.rb:560:      h[project_id] = memberships.where(:project_id => project_id).first
redmine/app/models/wiki.rb:56:    page = pages.where("LOWER(title) = LOWER(?)", title).first
redmine/app/models/wiki.rb:59:      redirect = redirects.where("LOWER(title) = LOWER(?)", title).first
redmine/app/models/issue_import.rb:148:          elsif issue_id = items.where(:position => parent_issue_id).first.try(:obj_id)
redmine/app/models/issue_import.rb:193:    child_id = items.where(:position => child_position).first.try(:obj_id)
redmine/app/models/attachment.rb:271:      attachment = Attachment.where(:id => attachment_id, :digest => attachment_digest).first
redmine/app/models/time_entry_query.rb:150:      issue = Issue.where(:id => value.first.to_i).first
redmine/app/models/repository.rb:252:      changesets.where("revision = ?", s).first
redmine/app/models/repository.rb:254:      changesets.where("revision LIKE ?", s + '%').first
redmine/app/models/role.rb:296:    role = unscoped.where(:builtin => builtin).first
redmine/app/models/repository/git.rb:92:      changesets.where(:revision => name.to_s).first ||
redmine/app/models/repository/git.rb:93:        changesets.where('scmid LIKE ?', "#{name}%").first
redmine/app/models/repository/mercurial.rb:100:      cs = changesets.where(:scmid => s).first
redmine/app/models/repository/mercurial.rb:102:      cs = changesets.where(:revision => s).first
redmine/app/models/repository/mercurial.rb:105:    changesets.where('scmid LIKE ?', "#{s}%").first
redmine/app/models/enumeration.rb:47:      where(:is_default => true, :type => 'Enumeration').first
redmine/app/models/enumeration.rb:50:      where(:is_default => true).first
redmine/app/controllers/imports_controller.rb:100:    @import = Import.where(:user_id => User.current.id, :filename => params[:id]).first

History

#1 Updated by Toshi MARUYAMA 10 months ago

  • Category set to Code cleanup/refactoring
  • Status changed from New to Needs feedback

Please post by attachment patch file.

#2 Updated by Toshi MARUYAMA 10 months ago

jwjw yy wrote:

sicne where.first will issue query with order by primary key which is actually unnecessary.

Really? Do all your description "where"s call "order by"?

#3 Updated by jwjw yy 9 months ago

Toshi MARUYAMA wrote:

jwjw yy wrote:

sicne where.first will issue query with order by primary key which is actually unnecessary.

Really? Do all your description "where"s call "order by"?

yes

Also available in: Atom PDF