diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/commit.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 12 |
2 files changed, 6 insertions, 10 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 9d721661629..aff329d71fa 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -157,11 +157,11 @@ class Commit end def author - User.find_for_commit(author_email, author_name) + @author ||= User.find_by_any_email(author_email) end def committer - User.find_for_commit(committer_email, committer_name) + @committer ||= User.find_by_any_email(committer_email) end def notes diff --git a/app/models/user.rb b/app/models/user.rb index f1bcecc13b3..dc84f5141d8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -225,7 +225,8 @@ class User < ActiveRecord::Base end end - def find_for_commit(email, name) + # Find a User by their primary email or any associated secondary email + def find_by_any_email(email) user_table = arel_table email_table = Email.arel_table @@ -237,13 +238,8 @@ class User < ActiveRecord::Base join(email_table, Arel::Nodes::OuterJoin). # ON "users"."id" = "emails"."user_id" on(user_table[:id].eq(email_table[:user_id])). - # WHERE ("user"."email" = '<email>' OR "user"."name" = '<name>') - # OR "emails"."email" = '<email>' - where( - user_table[:email].eq(email). - or(user_table[:name].eq(name)). - or(email_table[:email].eq(email)) - ) + # WHERE ("user"."email" = '<email>' OR "emails"."email" = '<email>') + where(user_table[:email].eq(email).or(email_table[:email].eq(email))) find_by_sql(query.to_sql).first end |