diff --git a/app/models/PullRequest.java b/app/models/PullRequest.java index edba150c8..3fb5527bc 100644 --- a/app/models/PullRequest.java +++ b/app/models/PullRequest.java @@ -149,7 +149,7 @@ public class PullRequest extends Model implements ResourceConvertible { joinColumns = @JoinColumn(name = "pull_request_id"), inverseJoinColumns = @JoinColumn(name = "user_id") ) - public List reviewers = new ArrayList<>(); + public Set reviewers = new HashSet<>(); @OneToMany(mappedBy = "pullRequest") public List commentThreads = new ArrayList<>(); @@ -999,7 +999,7 @@ public static void changeStateToClosed() { } public void clearReviewers() { - this.reviewers = new ArrayList<>(); + this.reviewers = new HashSet<>(); this.update(); } @@ -1008,8 +1008,9 @@ public int getRequiredReviewerCount() { } public void addReviewer(User user) { - this.reviewers.add(user); - this.update(); + if(this.reviewers.add(user)) { + this.update(); + } } public void removeReviewer(User user) { diff --git a/app/models/User.java b/app/models/User.java index df98e7af5..fe30ae60b 100644 --- a/app/models/User.java +++ b/app/models/User.java @@ -660,4 +660,24 @@ public void createOrganization(Organization organization) { private void add(OrganizationUser ou) { this.organizationUsers.add(ou); } + + @Override + public boolean equals(Object o) { + if(!(o instanceof User)) { + return false; + } + if(o == this) { + return true; + } + User user = (User) o; + return this.id.equals(user.id) && this.loginId.equals(user.loginId); + } + + @Override + public int hashCode() { + int result = 31; + result = result * 37 + this.id.hashCode(); + result = result * 37 + this.loginId.hashCode(); + return result; + } }