mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Use find_by instead of where.first to remove unnecessary sorting (#26747).
Patch by Yuichi HARADA. git-svn-id: http://svn.redmine.org/redmine/trunk@17586 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
323ef3182b
commit
e159928e6b
@ -964,7 +964,7 @@ module ApplicationHelper
|
|||||||
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
||||||
end
|
end
|
||||||
when 'user'
|
when 'user'
|
||||||
u = User.visible.where(:id => oid, :type => 'User').first
|
u = User.visible.find_by(:id => oid, :type => 'User')
|
||||||
link = link_to_user(u, :only_path => only_path) if u
|
link = link_to_user(u, :only_path => only_path) if u
|
||||||
end
|
end
|
||||||
elsif sep == ':'
|
elsif sep == ':'
|
||||||
@ -1025,12 +1025,12 @@ module ApplicationHelper
|
|||||||
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
link = link_to_project(p, {:only_path => only_path}, :class => 'project')
|
||||||
end
|
end
|
||||||
when 'user'
|
when 'user'
|
||||||
u = User.visible.where("LOWER(login) = :s AND type = 'User'", :s => name.downcase).first
|
u = User.visible.find_by("LOWER(login) = :s AND type = 'User'", :s => name.downcase)
|
||||||
link = link_to_user(u, :only_path => only_path) if u
|
link = link_to_user(u, :only_path => only_path) if u
|
||||||
end
|
end
|
||||||
elsif sep == "@"
|
elsif sep == "@"
|
||||||
name = remove_double_quotes(identifier)
|
name = remove_double_quotes(identifier)
|
||||||
u = User.visible.where("LOWER(login) = :s AND type = 'User'", :s => name.downcase).first
|
u = User.visible.find_by("LOWER(login) = :s AND type = 'User'", :s => name.downcase)
|
||||||
link = link_to_user(u, :only_path => only_path) if u
|
link = link_to_user(u, :only_path => only_path) if u
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -276,7 +276,7 @@ class Attachment < ActiveRecord::Base
|
|||||||
def self.find_by_token(token)
|
def self.find_by_token(token)
|
||||||
if token.to_s =~ /^(\d+)\.([0-9a-f]+)$/
|
if token.to_s =~ /^(\d+)\.([0-9a-f]+)$/
|
||||||
attachment_id, attachment_digest = $1, $2
|
attachment_id, attachment_digest = $1, $2
|
||||||
attachment = Attachment.where(:id => attachment_id, :digest => attachment_digest).first
|
attachment = Attachment.find_by(:id => attachment_id, :digest => attachment_digest)
|
||||||
if attachment && attachment.container.nil?
|
if attachment && attachment.container.nil?
|
||||||
attachment
|
attachment
|
||||||
end
|
end
|
||||||
|
|||||||
@ -132,7 +132,7 @@ class Principal < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
Principal.visible(user).where(:id => id).first == self
|
Principal.visible(user).find_by(:id => id) == self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true if the principal is a member of project
|
# Returns true if the principal is a member of project
|
||||||
|
|||||||
@ -247,7 +247,7 @@ class Repository < ActiveRecord::Base
|
|||||||
return nil if name.blank?
|
return nil if name.blank?
|
||||||
s = name.to_s
|
s = name.to_s
|
||||||
if s.match(/^\d*$/)
|
if s.match(/^\d*$/)
|
||||||
changesets.where("revision = ?", s).first
|
changesets.find_by(:revision => s)
|
||||||
else
|
else
|
||||||
changesets.where("revision LIKE ?", s + '%').first
|
changesets.where("revision LIKE ?", s + '%').first
|
||||||
end
|
end
|
||||||
|
|||||||
@ -89,7 +89,7 @@ class Repository::Git < Repository
|
|||||||
|
|
||||||
def find_changeset_by_name(name)
|
def find_changeset_by_name(name)
|
||||||
if name.present?
|
if name.present?
|
||||||
changesets.where(:revision => name.to_s).first ||
|
changesets.find_by(:revision => name.to_s) ||
|
||||||
changesets.where('scmid LIKE ?', "#{name}%").first
|
changesets.where('scmid LIKE ?', "#{name}%").first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -99,7 +99,7 @@ class Repository::Mercurial < Repository
|
|||||||
if /[^\d]/ =~ s or s.size > 8
|
if /[^\d]/ =~ s or s.size > 8
|
||||||
cs = changesets.where(:scmid => s).first
|
cs = changesets.where(:scmid => s).first
|
||||||
else
|
else
|
||||||
cs = changesets.where(:revision => s).first
|
cs = changesets.find_by(:revision => s)
|
||||||
end
|
end
|
||||||
return cs if cs
|
return cs if cs
|
||||||
changesets.where('scmid LIKE ?', "#{s}%").first
|
changesets.where('scmid LIKE ?', "#{s}%").first
|
||||||
|
|||||||
@ -293,7 +293,7 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.find_or_create_system_role(builtin, name)
|
def self.find_or_create_system_role(builtin, name)
|
||||||
role = unscoped.where(:builtin => builtin).first
|
role = unscoped.find_by(:builtin => builtin)
|
||||||
if role.nil?
|
if role.nil?
|
||||||
role = unscoped.create(:name => name) do |r|
|
role = unscoped.create(:name => name) do |r|
|
||||||
r.builtin = builtin
|
r.builtin = builtin
|
||||||
|
|||||||
@ -112,7 +112,7 @@ class Token < ActiveRecord::Base
|
|||||||
key = key.to_s
|
key = key.to_s
|
||||||
return nil unless action.present? && key =~ /\A[a-z0-9]+\z/i
|
return nil unless action.present? && key =~ /\A[a-z0-9]+\z/i
|
||||||
|
|
||||||
token = Token.where(:action => action, :value => key).first
|
token = Token.find_by(:action => action, :value => key)
|
||||||
if token && (token.action == action) && (token.value == key) && token.user
|
if token && (token.action == action) && (token.value == key) && token.user
|
||||||
if validity_days.nil? || (token.created_on > validity_days.days.ago)
|
if validity_days.nil? || (token.created_on > validity_days.days.ago)
|
||||||
token
|
token
|
||||||
|
|||||||
@ -492,7 +492,7 @@ class User < Principal
|
|||||||
user = where(:login => login).detect {|u| u.login == login}
|
user = where(:login => login).detect {|u| u.login == login}
|
||||||
unless user
|
unless user
|
||||||
# Fail over to case-insensitive if none was found
|
# Fail over to case-insensitive if none was found
|
||||||
user = where("LOWER(login) = ?", login.downcase).first
|
user = find_by("LOWER(login) = ?", login.downcase)
|
||||||
end
|
end
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
@ -798,7 +798,7 @@ class User < Principal
|
|||||||
# Returns the anonymous user. If the anonymous user does not exist, it is created. There can be only
|
# Returns the anonymous user. If the anonymous user does not exist, it is created. There can be only
|
||||||
# one anonymous user per database.
|
# one anonymous user per database.
|
||||||
def self.anonymous
|
def self.anonymous
|
||||||
anonymous_user = AnonymousUser.unscoped.first
|
anonymous_user = AnonymousUser.unscoped.find_by(:lastname => 'Anonymous')
|
||||||
if anonymous_user.nil?
|
if anonymous_user.nil?
|
||||||
anonymous_user = AnonymousUser.unscoped.create(:lastname => 'Anonymous', :firstname => '', :login => '', :status => 0)
|
anonymous_user = AnonymousUser.unscoped.create(:lastname => 'Anonymous', :firstname => '', :login => '', :status => 0)
|
||||||
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
|
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class Wiki < ActiveRecord::Base
|
|||||||
@page_found_with_redirect = false
|
@page_found_with_redirect = false
|
||||||
title = start_page if title.blank?
|
title = start_page if title.blank?
|
||||||
title = Wiki.titleize(title)
|
title = Wiki.titleize(title)
|
||||||
page = pages.where("LOWER(title) = LOWER(?)", title).first
|
page = pages.find_by("LOWER(title) = LOWER(?)", title)
|
||||||
if page.nil? && options[:with_redirect] != false
|
if page.nil? && options[:with_redirect] != false
|
||||||
# search for a redirect
|
# search for a redirect
|
||||||
redirect = redirects.where("LOWER(title) = LOWER(?)", title).first
|
redirect = redirects.where("LOWER(title) = LOWER(?)", title).first
|
||||||
|
|||||||
@ -964,7 +964,7 @@ module Redmine
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
if custom_value.value.present?
|
if custom_value.value.present?
|
||||||
attachment = Attachment.where(:id => custom_value.value.to_s).first
|
attachment = Attachment.find_by(:id => custom_value.value.to_s)
|
||||||
extensions = custom_value.custom_field.extensions_allowed
|
extensions = custom_value.custom_field.extensions_allowed
|
||||||
if attachment && extensions.present? && !attachment.extension_in?(extensions)
|
if attachment && extensions.present? && !attachment.extension_in?(extensions)
|
||||||
errors << "#{::I18n.t('activerecord.errors.messages.invalid')} (#{l(:setting_attachment_extensions_allowed)}: #{extensions})"
|
errors << "#{::I18n.t('activerecord.errors.messages.invalid')} (#{l(:setting_attachment_extensions_allowed)}: #{extensions})"
|
||||||
@ -978,14 +978,14 @@ module Redmine
|
|||||||
def after_save_custom_value(custom_field, custom_value)
|
def after_save_custom_value(custom_field, custom_value)
|
||||||
if custom_value.saved_change_to_value?
|
if custom_value.saved_change_to_value?
|
||||||
if custom_value.value.present?
|
if custom_value.value.present?
|
||||||
attachment = Attachment.where(:id => custom_value.value.to_s).first
|
attachment = Attachment.find_by(:id => custom_value.value.to_s)
|
||||||
if attachment
|
if attachment
|
||||||
attachment.container = custom_value
|
attachment.container = custom_value
|
||||||
attachment.save!
|
attachment.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if custom_value.value_before_last_save.present?
|
if custom_value.value_before_last_save.present?
|
||||||
attachment = Attachment.where(:id => custom_value.value_before_last_save.to_s).first
|
attachment = Attachment.find_by(:id => custom_value.value_before_last_save.to_s)
|
||||||
if attachment
|
if attachment
|
||||||
attachment.destroy
|
attachment.destroy
|
||||||
end
|
end
|
||||||
|
|||||||
@ -453,7 +453,7 @@ namespace :redmine do
|
|||||||
puts
|
puts
|
||||||
|
|
||||||
# Trac 'resolution' field as a Redmine custom field
|
# Trac 'resolution' field as a Redmine custom field
|
||||||
r = IssueCustomField.where(:name => "Resolution").first
|
r = IssueCustomField.find_by(:name => "Resolution")
|
||||||
r = IssueCustomField.new(:name => 'Resolution',
|
r = IssueCustomField.new(:name => 'Resolution',
|
||||||
:field_format => 'list',
|
:field_format => 'list',
|
||||||
:is_filter => true) if r.nil?
|
:is_filter => true) if r.nil?
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user