Changseong Kim 2014-03-18
fix the issue 1048.
Cause:
Before referring original issue properties for the first time, to call update() of modifieid issue brings about the issue because of lazy loading.

Solution:
The codes that load original issue properties are moved above calling update() of modified issue.
@0243e0ed710eab5f1c496106d16f601204b10ded
app/controllers/AbstractPostingApp.java
--- app/controllers/AbstractPostingApp.java
+++ app/controllers/AbstractPostingApp.java
@@ -116,10 +116,10 @@
      * @param posting
      * @param postingForm
      * @param redirectTo
-     * @param updatePosting
+     * @param preUpdateHook
      * @return
      */
-    protected static Result editPosting(AbstractPosting original, AbstractPosting posting, Form<? extends AbstractPosting> postingForm, Call redirectTo, Runnable updatePosting) {
+    protected static Result editPosting(AbstractPosting original, AbstractPosting posting, Form<? extends AbstractPosting> postingForm, Call redirectTo, Runnable preUpdateHook) {
         if (postingForm.hasErrors()) {
             return badRequest(ErrorViews.BadRequest.render("error.validation", original.project));
         }
@@ -140,7 +140,7 @@
         posting.authorLoginId = original.authorLoginId;
         posting.authorName = original.authorName;
         posting.project = original.project;
-        updatePosting.run();
+        preUpdateHook.run();
         posting.update();
         posting.updateProperties();
 
app/controllers/IssueApp.java
--- app/controllers/IssueApp.java
+++ app/controllers/IssueApp.java
@@ -600,28 +600,25 @@
 
     private static void addAssigneeChangedNotification(Issue modifiedIssue, Issue originalIssue) {
         if(!originalIssue.assignedUserEquals(modifiedIssue.assignee)) {
-            Issue updatedIssue = Issue.finder.byId(originalIssue.id);
             User oldAssignee = null;
             if(hasAssignee(originalIssue)) {
                 oldAssignee = originalIssue.assignee.user;
             }
-            NotificationEvent notiEvent = NotificationEvent.afterAssigneeChanged(oldAssignee, updatedIssue);
+            NotificationEvent notiEvent = NotificationEvent.afterAssigneeChanged(oldAssignee, modifiedIssue);
             IssueEvent.addFromNotificationEvent(notiEvent, modifiedIssue, UserApp.currentUser().loginId);
         }
     }
 
     private static void addStateChangedNotification(Issue modifiedIssue, Issue originalIssue) {
         if(modifiedIssue.state != originalIssue.state) {
-            Issue updatedIssue = Issue.finder.byId(originalIssue.id);
-            NotificationEvent notiEvent = NotificationEvent.afterStateChanged(originalIssue.state, updatedIssue);
+            NotificationEvent notiEvent = NotificationEvent.afterStateChanged(originalIssue.state, modifiedIssue);
             IssueEvent.addFromNotificationEvent(notiEvent, modifiedIssue, UserApp.currentUser().loginId);
         }
     }
 
     private static void addBodyChangedNotification(Issue modifiedIssue, Issue originalIssue) {
         if (!modifiedIssue.body.equals(originalIssue.body)) {
-            Issue updatedIssue = Issue.finder.byId(originalIssue.id);
-            NotificationEvent notiEvent = NotificationEvent.afterIssueBodyChanged(originalIssue.body, updatedIssue);
+            NotificationEvent notiEvent = NotificationEvent.afterIssueBodyChanged(originalIssue.body, modifiedIssue);
             IssueEvent.addFromNotificationEvent(notiEvent, modifiedIssue, UserApp.currentUser().loginId);
         }
     }
@@ -660,9 +657,9 @@
 
         Call redirectTo = routes.IssueApp.issue(project.owner, project.name, number);
 
-        // updateIssueBeforeSave.run would be called just before this issue is saved.
+        // preUpdateHook.run would be called just before this issue is updated.
         // It updates some properties only for issues, such as assignee or labels, but not for non-issues.
-        Runnable updateIssueBeforeSave = new Runnable() {
+        Runnable preUpdateHook = new Runnable() {
             @Override
             public void run() {
                 // Below addAll() method is needed to avoid the exception, 'Timeout trying to lock table ISSUE'.
@@ -671,16 +668,14 @@
                 issue.voters.addAll(originalIssue.voters);
                 issue.comments = originalIssue.comments;
                 addLabels(issue, request());
+
+                addAssigneeChangedNotification(issue, originalIssue);
+                addStateChangedNotification(issue, originalIssue);
+                addBodyChangedNotification(issue, originalIssue);
             }
         };
 
-        Result result = editPosting(originalIssue, issue, issueForm, redirectTo, updateIssueBeforeSave);
-
-        addAssigneeChangedNotification(issue, originalIssue);
-        addStateChangedNotification(issue, originalIssue);
-        addBodyChangedNotification(issue, originalIssue);
-
-        return result;
+        return editPosting(originalIssue, issue, issueForm, redirectTo, preUpdateHook);
     }
 
     /*
app/views/issue/partial_comments.scala.html
--- app/views/issue/partial_comments.scala.html
+++ app/views/issue/partial_comments.scala.html
@@ -99,35 +99,35 @@
     </li>
     }
     case (event: IssueEvent) => {
-    <li class="event" id="event-@event.id">
-        @defining(User.findByLoginId(event.senderLoginId)) { user =>
-            @event.eventType match {
-                case EventType.ISSUE_STATE_CHANGED => {
-                    <span class="state @event.newValue">@Messages("issue.state." + event.newValue)</span> @Html(Messages("issue.event." + event.newValue, linkToUser(user.loginId, user.name)))
-                }
-                case EventType.ISSUE_ASSIGNEE_CHANGED => {
-                    <span class="state changed">@Messages("issue.state.assigned")</span>
-                    @Html(Messages(assginedMesssage(event.newValue, user), linkToUser(user.loginId, user.name), linkToUser(event.newValue,User.findByLoginId(event.newValue).name, true)))
-                }
-                case EventType.ISSUE_REFERRED_FROM_COMMIT => {
-                    <span class="state changed">@Messages("issue.event.referred.title")</span>
-                    @Html(Messages("issue.event.referred",linkToUser(user.loginId, user.name),linkToCommit(event.newValue)))
-                }
-                case EventType.ISSUE_REFERRED_FROM_PULL_REQUEST => {
-                    <span class="state changed">@Messages("issue.event.referred.title")</span>
-                    @defining(PullRequest.findById(Long.valueOf(event.newValue))) { pull =>
-                        @Html(Messages("issue.event.referred",linkToUser(user.loginId, user.name),linkToPullRequest(pull)))
+        @if(event.eventType != EventType.ISSUE_BODY_CHANGED) {
+            <li class="event" id="event-@event.id">
+                @defining(User.findByLoginId(event.senderLoginId)) { user =>
+                    @event.eventType match {
+                        case EventType.ISSUE_STATE_CHANGED => {
+                            <span class="state @event.newValue">@Messages("issue.state." + event.newValue)</span> @Html(Messages("issue.event." + event.newValue, linkToUser(user.loginId, user.name)))
+                        }
+                        case EventType.ISSUE_ASSIGNEE_CHANGED => {
+                            <span class="state changed">@Messages("issue.state.assigned")</span>
+                            @Html(Messages(assginedMesssage(event.newValue, user), linkToUser(user.loginId, user.name), linkToUser(event.newValue,User.findByLoginId(event.newValue).name, true)))
+                        }
+                        case EventType.ISSUE_REFERRED_FROM_COMMIT => {
+                            <span class="state changed">@Messages("issue.event.referred.title")</span>
+                            @Html(Messages("issue.event.referred",linkToUser(user.loginId, user.name),linkToCommit(event.newValue)))
+                        }
+                        case EventType.ISSUE_REFERRED_FROM_PULL_REQUEST => {
+                            <span class="state changed">@Messages("issue.event.referred.title")</span>
+                            @defining(PullRequest.findById(Long.valueOf(event.newValue))) { pull =>
+                                @Html(Messages("issue.event.referred",linkToUser(user.loginId, user.name),linkToPullRequest(pull)))
+                            }
+                        }
+                        case _ => {
+                            @event.newValue by @linkToUser(user.loginId, user.name)
+                        }
                     }
                 }
-                case EventType.ISSUE_BODY_CHANGED => {
-                }
-                case _ => {
-                    @event.newValue by @linkToUser(user.loginId, user.name)
-                }
-            }
+                <span class="date"><a href="#event-@event.id">@utils.TemplateHelper.agoString(JodaDateUtil.ago(event.getDate()))</a></span>
+            </li>
         }
-        <span class="date"><a href="#event-@event.id">@utils.TemplateHelper.agoString(JodaDateUtil.ago(event.getDate()))</a></span>
-    </li>
     }
     }
 }
Add a comment
List