doortts doortts 2017-01-08
tuning: Reduce issue list page response time
@b5a5cbb217823458383ed09bfbaf9584b65fb27f
app/models/Comment.java
--- app/models/Comment.java
+++ app/models/Comment.java
@@ -55,6 +55,7 @@
     public Long authorId;
     public String authorLoginId;
     public String authorName;
+    public Long projectId;
 
     public Comment() {
         createdDate = new Date();
app/models/IssueComment.java
--- app/models/IssueComment.java
+++ app/models/IssueComment.java
@@ -46,6 +46,7 @@
     public IssueComment(Issue issue, User author, String contents) {
         super(author, contents);
         this.issue = issue;
+        this.projectId = issue.project.id;
     }
 
     /**
app/models/PostingComment.java
--- app/models/PostingComment.java
+++ app/models/PostingComment.java
@@ -37,6 +37,7 @@
     public PostingComment(Posting posting, User author, String contents) {
         super(author, contents);
         this.posting = posting;
+        this.projectId = posting.project.id;
     }
 
     /**
app/models/support/SearchCondition.java
--- app/models/support/SearchCondition.java
+++ app/models/support/SearchCondition.java
@@ -326,24 +326,15 @@
         for (Comment comment : IssueComment.find.where()
                 .eq("authorId", commenter.id)
                 .findList()) {
-
-            switch (comment.asResource().getType()) {
-                case ISSUE_COMMENT:
-                    if(project == null) {
-                        issueIds.add(comment.getParent().id);
-                        break;
-                    } else {
-                        if(comment.getParent().project.id.equals(project.id)){
-                            issueIds.add(comment.getParent().id);
-                        }
-                    }
-                    break;
-                default:
-                    play.Logger.warn("'" + comment.asResource().getType() + "' is not supported.");
-                    break;
+            if (project == null) {
+                issueIds.add(comment.getParent().id);
+                break;
+            } else {
+                if (comment.projectId.equals(project.id)) {
+                    issueIds.add(comment.getParent().id);
+                }
             }
         }
-
         return new ArrayList<>(issueIds);
     }
 
@@ -417,7 +408,9 @@
                 el.isNull("assignee");
             } else {
                 el.eq("assignee.user.id", assigneeId);
-                el.eq("assignee.project.id", project.id);
+                if(project != null) {
+                    el.eq("assignee.project.id", project.id);
+                }
             }
         }
 
 
conf/evolutions/default/9.sql (added)
+++ conf/evolutions/default/9.sql
@@ -0,0 +1,38 @@
+# --- !Ups
+ALTER TABLE issue_comment ADD COLUMN project_id bigint NOT NULL;
+DELETE FROM issue_comment WHERE issue_id = 0;
+COMMIT;
+UPDATE issue_comment a
+SET a.project_id = (SELECT project_id FROM issue b WHERE a.issue_id = b.id);
+CREATE INDEX ix_issue_comment_project_id ON issue_comment (project_id);
+
+ALTER TABLE posting_comment ADD COLUMN project_id bigint NOT NULL;
+DELETE FROM posting_comment WHERE posting_id = 0;
+COMMIT;
+UPDATE posting_comment a
+SET a.project_id = (SELECT project_id FROM posting b WHERE a.posting_id = b.id);
+CREATE INDEX ix_posting_comment_project_id ON posting_comment (project_id);
+
+CREATE INDEX ix_issue_comment_author_id ON issue_comment (author_id);
+CREATE INDEX ix_posting_comment_author_id ON posting_comment (author_id);
+CREATE INDEX ix_pull_request_number ON pull_request (number);
+CREATE INDEX ix_issue_author_id_state ON issue (author_id, state);
+CREATE INDEX ix_issue_created_date ON issue (created_date);
+
+CREATE INDEX ix_n4user_email ON n4user (email);
+CREATE UNIQUE INDEX uq_email_email_valid ON email (email, valid)
+
+# --- !Downs
+DROP INDEX ix_issue_comment_project_id ON issue_comment;
+DROP INDEX ix_posting_comment_project_id ON posting_comment;
+ALTER TABLE issue_comment DROP COLUMN project_id;
+ALTER TABLE posting_comment DROP COLUMN project_id;
+
+DROP INDEX ix_issue_comment_author_id ON issue_comment;
+DROP INDEX ix_posting_comment_author_id ON posting_comment;
+DROP INDEX ix_pull_request_number ON pull_request;
+DROP INDEX ix_issue_author_id_state ON issue;
+DROP INDEX ix_issue_created_date ON issue;
+
+DROP INDEX ix_n4user_email ON n4user;
+DROP  INDEX uq_email_email_valid ON email;
Add a comment
List