[Notice] Announcing the End of Demo Server [Read me]

Merge branch 'perf/issue' into 'next'
from pull-request 1714 * perf/issue: perf: Avoid unnecessary permission check perf/user: Make hash() and equals() faster perf/issue: Improve performance using @Transactional Reviewed-by: 채수원
@41bf4b42a0a68e9f09cc39e1a68fb528a1856915
--- app/controllers/IssueApp.java
+++ app/controllers/IssueApp.java
... | ... | @@ -91,6 +91,7 @@ |
91 | 91 |
return searchCondition.assigneeId == null && searchCondition.authorId == null && searchCondition.mentionId == null; |
92 | 92 |
} |
93 | 93 |
|
94 |
+ @Transactional |
|
94 | 95 |
@IsAllowed(Operation.READ) |
95 | 96 |
public static Result issues(String ownerName, String projectName, String state, String format, int pageNum) throws WriteException, IOException { |
96 | 97 |
Project project = Project.findByOwnerAndProjectName(ownerName, projectName); |
... | ... | @@ -205,6 +206,7 @@ |
205 | 206 |
return ok(listData); |
206 | 207 |
} |
207 | 208 |
|
209 |
+ @Transactional |
|
208 | 210 |
@With(NullProjectCheckAction.class) |
209 | 211 |
public static Result issue(String ownerName, String projectName, Long number) { |
210 | 212 |
Project project = Project.findByOwnerAndProjectName(ownerName, projectName); |
--- app/models/AbstractPosting.java
+++ app/models/AbstractPosting.java
... | ... | @@ -222,13 +222,9 @@ |
222 | 222 |
// default implementation for convenience |
223 | 223 |
} |
224 | 224 |
|
225 |
- /** |
|
226 |
- * @see {@link #getWatchers()} |
|
227 |
- * @see <a href="https://github.com/nforge/yobi/blob/master/docs/technical/watch.md>watch.md</a> |
|
228 |
- */ |
|
229 | 225 |
@Transient |
230 | 226 |
public Set<User> getWatchers() { |
231 |
- return getWatchers(new HashSet<User>()); |
|
227 |
+ return getWatchers(true); |
|
232 | 228 |
} |
233 | 229 |
|
234 | 230 |
/** |
... | ... | @@ -236,7 +232,16 @@ |
236 | 232 |
* @see <a href="https://github.com/nforge/yobi/blob/master/docs/technical/watch.md>watch.md</a> |
237 | 233 |
*/ |
238 | 234 |
@Transient |
239 |
- public Set<User> getWatchers(Set<User> baseWatchers) { |
|
235 |
+ public Set<User> getWatchers(boolean allowedWatchersOnly) { |
|
236 |
+ return getWatchers(new HashSet<User>(), allowedWatchersOnly); |
|
237 |
+ } |
|
238 |
+ |
|
239 |
+ /** |
|
240 |
+ * @see {@link #getWatchers()} |
|
241 |
+ * @see <a href="https://github.com/nforge/yobi/blob/master/docs/technical/watch.md>watch.md</a> |
|
242 |
+ */ |
|
243 |
+ @Transient |
|
244 |
+ public Set<User> getWatchers(Set<User> baseWatchers, boolean allowedWatchersOnly) { |
|
240 | 245 |
Set<User> actualWatchers = new HashSet<>(); |
241 | 246 |
|
242 | 247 |
actualWatchers.addAll(baseWatchers); |
... | ... | @@ -249,7 +254,7 @@ |
249 | 254 |
} |
250 | 255 |
} |
251 | 256 |
|
252 |
- return Watch.findActualWatchers(actualWatchers, asResource()); |
|
257 |
+ return Watch.findActualWatchers(actualWatchers, asResource(), allowedWatchersOnly); |
|
253 | 258 |
} |
254 | 259 |
|
255 | 260 |
protected void updateMention() { |
--- app/models/Issue.java
+++ app/models/Issue.java
... | ... | @@ -348,20 +348,25 @@ |
348 | 348 |
return AbstractPosting.findByNumber(finder, project, number); |
349 | 349 |
} |
350 | 350 |
|
351 |
+ @Transient |
|
352 |
+ public Set<User> getWatchers() { |
|
353 |
+ return getWatchers(true); |
|
354 |
+ } |
|
355 |
+ |
|
351 | 356 |
/** |
352 | 357 |
* Returns all users watching or voting the issue. |
353 | 358 |
* |
354 | 359 |
* @return The set watching and voting the issue. |
355 | 360 |
*/ |
356 | 361 |
@Transient |
357 |
- public Set<User> getWatchers() { |
|
362 |
+ public Set<User> getWatchers(boolean allowedWatchersOnly) { |
|
358 | 363 |
Set<User> baseWatchers = new HashSet<>(); |
359 | 364 |
if (assignee != null) { |
360 | 365 |
baseWatchers.add(assignee.user); |
361 | 366 |
} |
362 | 367 |
baseWatchers.addAll(this.voters); |
363 | 368 |
|
364 |
- return super.getWatchers(baseWatchers); |
|
369 |
+ return super.getWatchers(baseWatchers, allowedWatchersOnly); |
|
365 | 370 |
} |
366 | 371 |
|
367 | 372 |
public boolean assignedUserEquals(Assignee otherAssignee) { |
--- app/models/PullRequest.java
+++ app/models/PullRequest.java
... | ... | @@ -584,6 +584,10 @@ |
584 | 584 |
} |
585 | 585 |
|
586 | 586 |
public Set<User> getWatchers() { |
587 |
+ return getWatchers(true); |
|
588 |
+ } |
|
589 |
+ |
|
590 |
+ public Set<User> getWatchers(boolean allowedWatchersOnly) { |
|
587 | 591 |
Set<User> actualWatchers = new HashSet<>(); |
588 | 592 |
|
589 | 593 |
actualWatchers.add(this.contributor); |
... | ... | @@ -596,7 +600,7 @@ |
596 | 600 |
} |
597 | 601 |
} |
598 | 602 |
|
599 |
- return Watch.findActualWatchers(actualWatchers, asResource()); |
|
603 |
+ return Watch.findActualWatchers(actualWatchers, asResource(), allowedWatchersOnly); |
|
600 | 604 |
} |
601 | 605 |
|
602 | 606 |
/** |
--- app/models/User.java
+++ app/models/User.java
... | ... | @@ -770,21 +770,16 @@ |
770 | 770 |
|
771 | 771 |
@Override |
772 | 772 |
public boolean equals(Object o) { |
773 |
- if(!(o instanceof User)) { |
|
774 |
- return false; |
|
775 |
- } |
|
776 |
- if(o == this) { |
|
777 |
- return true; |
|
778 |
- } |
|
773 |
+ if (this == o) return true; |
|
774 |
+ if (o == null || getClass() != o.getClass()) return false; |
|
775 |
+ |
|
779 | 776 |
User user = (User) o; |
780 |
- return this.id.equals(user.id) && this.loginId.equals(user.loginId); |
|
777 |
+ |
|
778 |
+ return !(id != null ? !id.equals(user.id) : user.id != null); |
|
781 | 779 |
} |
782 | 780 |
|
783 | 781 |
@Override |
784 | 782 |
public int hashCode() { |
785 |
- int result = super.hashCode(); |
|
786 |
- result = result * 37 + (this.id != null ? this.id.hashCode() : 0); |
|
787 |
- result = result * 37 + (this.loginId != null ? this.loginId.hashCode() : 0); |
|
788 |
- return result; |
|
783 |
+ return id != null ? id.hashCode() : 0; |
|
789 | 784 |
} |
790 | 785 |
} |
--- app/models/Watch.java
+++ app/models/Watch.java
... | ... | @@ -157,7 +157,10 @@ |
157 | 157 |
return isWatching(UserApp.currentUser(), resource.getType(), resource.getId()); |
158 | 158 |
} |
159 | 159 |
|
160 |
- public static Set<User> findActualWatchers(final Set<User> baseWatchers, final Resource resource) { |
|
160 |
+ public static Set<User> findActualWatchers( |
|
161 |
+ final Set<User> baseWatchers, |
|
162 |
+ final Resource resource, |
|
163 |
+ boolean allowedWatchersOnly) { |
|
161 | 164 |
Set<User> actualWatchers = new HashSet<>(); |
162 | 165 |
actualWatchers.addAll(baseWatchers); |
163 | 166 |
|
... | ... | @@ -172,12 +175,14 @@ |
172 | 175 |
actualWatchers.removeAll(findUnwatchers(resource)); |
173 | 176 |
|
174 | 177 |
// Filter the watchers who has no permission to read this resource. |
175 |
- CollectionUtils.filter(actualWatchers, new Predicate() { |
|
176 |
- @Override |
|
177 |
- public boolean evaluate(Object watcher) { |
|
178 |
- return AccessControl.isAllowed((User) watcher, resource, Operation.READ); |
|
179 |
- } |
|
180 |
- }); |
|
178 |
+ if (allowedWatchersOnly) { |
|
179 |
+ CollectionUtils.filter(actualWatchers, new Predicate() { |
|
180 |
+ @Override |
|
181 |
+ public boolean evaluate(Object watcher) { |
|
182 |
+ return AccessControl.isAllowed((User) watcher, resource, Operation.READ); |
|
183 |
+ } |
|
184 |
+ }); |
|
185 |
+ } |
|
181 | 186 |
return actualWatchers; |
182 | 187 |
} |
183 | 188 |
|
--- app/playRepository/Commit.java
+++ app/playRepository/Commit.java
... | ... | @@ -44,6 +44,10 @@ |
44 | 44 |
public abstract int getParentCount(); |
45 | 45 |
|
46 | 46 |
public Set<User> getWatchers(Project project) { |
47 |
+ return getWatchers(project, true); |
|
48 |
+ } |
|
49 |
+ |
|
50 |
+ public Set<User> getWatchers(Project project, boolean allowedWatchersOnly) { |
|
47 | 51 |
Set<User> actualWatchers = new HashSet<>(); |
48 | 52 |
|
49 | 53 |
// Add the author |
... | ... | @@ -76,7 +80,7 @@ |
76 | 80 |
} |
77 | 81 |
} |
78 | 82 |
|
79 |
- return Watch.findActualWatchers(actualWatchers, asResource(project)); |
|
83 |
+ return Watch.findActualWatchers(actualWatchers, asResource(project), allowedWatchersOnly); |
|
80 | 84 |
} |
81 | 85 |
|
82 | 86 |
public static Project getProjectFromResourceId(String resourceId) { |
--- app/views/board/view.scala.html
+++ app/views/board/view.scala.html
... | ... | @@ -72,8 +72,8 @@ |
72 | 72 |
<div class="board-footer board-actrow"> |
73 | 73 |
<div class="pull-left"> |
74 | 74 |
@if(isAllowed(UserApp.currentUser(), post.asResource(), Operation.WATCH)){ |
75 |
- <button id="watch-button" type="button" class="ybtn @if(post.getWatchers.contains(UserApp.currentUser())){ybtn-watching}" data-toggle="button" data-watching="@if(post.getWatchers.contains(UserApp.currentUser())){true}else{false}"> |
|
76 |
- @if(post.getWatchers.contains(UserApp.currentUser())) { @Messages("project.unwatch") } else { @Messages("project.watch") } |
|
75 |
+ <button id="watch-button" type="button" class="ybtn @if(post.getWatchers(false).contains(UserApp.currentUser())){ybtn-watching}" data-toggle="button" data-watching="@if(post.getWatchers(false).contains(UserApp.currentUser())){true}else{false}"> |
|
76 |
+ @if(post.getWatchers(false).contains(UserApp.currentUser())) { @Messages("project.unwatch") } else { @Messages("project.watch") } |
|
77 | 77 |
</button> |
78 | 78 |
} |
79 | 79 |
</div> |
--- app/views/code/diff.scala.html
+++ app/views/code/diff.scala.html
... | ... | @@ -176,7 +176,9 @@ |
176 | 176 |
</div> |
177 | 177 |
</div> |
178 | 178 |
|
179 |
- <button id="watch-button" type="button" class="pull-left ybtn @if(commit.getWatchers(project).contains(UserApp.currentUser())) { active ybtn-watching }" data-toggle="button">@Messages("notification.watch")</button> |
|
179 |
+ <button id="watch-button" type="button" class="pull-left ybtn @if(commit.getWatchers |
|
180 |
+ (project, false).contains(UserApp.currentUser())) { active ybtn-watching }" |
|
181 |
+ data-toggle="button">@Messages("notification.watch")</button> |
|
180 | 182 |
|
181 | 183 |
<a href="@routes.CodeHistoryApp.history(project.owner, project.name, selectedBranch, path)" class="ybtn pull-right">@Messages("button.list")</a> |
182 | 184 |
</div> |
--- app/views/code/svnDiff.scala.html
+++ app/views/code/svnDiff.scala.html
... | ... | @@ -141,7 +141,8 @@ |
141 | 141 |
@** // Comment **@ |
142 | 142 |
</div> |
143 | 143 |
|
144 |
- <button id="watch-button" type="button" class="ybtn @if(commit.getWatchers(project).contains(UserApp.currentUser())) { active }" data-toggle="button">@Messages("notification.watch")</button> |
|
144 |
+ <button id="watch-button" type="button" class="ybtn @if(commit.getWatchers(project, false) |
|
145 |
+ .contains(UserApp.currentUser())) { active }" data-toggle="button">@Messages("notification.watch")</button> |
|
145 | 146 |
|
146 | 147 |
<a href="@routes.CodeHistoryApp.history(project.owner, project.name, selectedBranch, path)" class="ybtn pull-right">@Messages("button.list")</a> |
147 | 148 |
|
--- app/views/git/view.scala.html
+++ app/views/git/view.scala.html
... | ... | @@ -57,8 +57,8 @@ |
57 | 57 |
<div class="board-footer board-actrow"> |
58 | 58 |
<div class="pull-left"> |
59 | 59 |
@if(isAllowed(UserApp.currentUser(), pull.asResource(), Operation.WATCH)) { |
60 |
- <button id="watch-button" type="button" class="ybtn @if(pull.getWatchers.contains(UserApp.currentUser())) { ybtn-watching }" data-toggle="button" data-watching="@if(pull.getWatchers.contains(UserApp.currentUser())){true}else{false}"> |
|
61 |
- @if(pull.getWatchers.contains(UserApp.currentUser())) { |
|
60 |
+ <button id="watch-button" type="button" class="ybtn @if(pull.getWatchers(false).contains(UserApp.currentUser())) { ybtn-watching }" data-toggle="button" data-watching="@if(pull.getWatchers(false).contains(UserApp.currentUser())){true}else{false}"> |
|
61 |
+ @if(pull.getWatchers(false).contains(UserApp.currentUser())) { |
|
62 | 62 |
@Messages("project.unwatch") |
63 | 63 |
} else { |
64 | 64 |
@Messages("project.watch") |
--- app/views/issue/view.scala.html
+++ app/views/issue/view.scala.html
... | ... | @@ -107,9 +107,9 @@ |
107 | 107 |
<div class="pull-left"> |
108 | 108 |
<div> |
109 | 109 |
@if(isAllowed(UserApp.currentUser(), issue.asResource(), Operation.WATCH)) { |
110 |
- <button id="watch-button" type="button" class="ybtn @if(issue.getWatchers.contains(UserApp.currentUser())) {ybtn-watching}" |
|
111 |
- data-toggle="button" data-watching="@if(issue.getWatchers.contains(UserApp.currentUser())){true}else{false}"> |
|
112 |
- @if(issue.getWatchers.contains(UserApp.currentUser())) { |
|
110 |
+ <button id="watch-button" type="button" class="ybtn @if(issue.getWatchers(false).contains(UserApp.currentUser())) {ybtn-watching}" |
|
111 |
+ data-toggle="button" data-watching="@if(issue.getWatchers(false).contains(UserApp.currentUser())){true}else{false}"> |
|
112 |
+ @if(issue.getWatchers(false).contains(UserApp.currentUser())) { |
|
113 | 113 |
@Messages("issue.unwatch") |
114 | 114 |
} else { |
115 | 115 |
@Messages("issue.watch") |
--- test/models/WatchTest.java
+++ test/models/WatchTest.java
... | ... | @@ -165,7 +165,8 @@ |
165 | 165 |
baseWatchers.add(base_watcher_not_member); |
166 | 166 |
|
167 | 167 |
// When |
168 |
- Set<User> actualWatchers = Watch.findActualWatchers(baseWatchers, resource_of_private_project); |
|
168 |
+ Set<User> actualWatchers = Watch.findActualWatchers(baseWatchers, |
|
169 |
+ resource_of_private_project, true); |
|
169 | 170 |
|
170 | 171 |
// Then |
171 | 172 |
assertThat(actualWatchers).containsOnly(watch_isssue, watch_project); |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?