Add view ISSUE_OUTLINE_VIEW.

This commit is contained in:
shimamoto
2013-07-25 20:28:19 +09:00
parent 07ef06ad95
commit a5f12a50e6
3 changed files with 48 additions and 38 deletions

View File

@@ -8,3 +8,17 @@ ALTER TABLE GROUP_MEMBER ADD CONSTRAINT IDX_GROUP_MEMBER_FK0 FOREIGN KEY (GROUP_
ALTER TABLE GROUP_MEMBER ADD CONSTRAINT IDX_GROUP_MEMBER_FK1 FOREIGN KEY (USER_NAME) REFERENCES ACCOUNT (USER_NAME); ALTER TABLE GROUP_MEMBER ADD CONSTRAINT IDX_GROUP_MEMBER_FK1 FOREIGN KEY (USER_NAME) REFERENCES ACCOUNT (USER_NAME);
ALTER TABLE ACCOUNT ADD COLUMN GROUP_ACCOUNT BOOLEAN NOT NULL DEFAULT FALSE; ALTER TABLE ACCOUNT ADD COLUMN GROUP_ACCOUNT BOOLEAN NOT NULL DEFAULT FALSE;
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
SELECT
A.USER_NAME,
A.REPOSITORY_NAME,
A.ISSUE_ID,
NVL(B.COMMENT_COUNT, 0) AS COMMENT_COUNT
FROM ISSUE A
LEFT OUTER JOIN (
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
) B
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID);

View File

@@ -7,6 +7,11 @@ object IssueId extends Table[(String, String, Int)]("ISSUE_ID") with IssueTempla
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository) def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
} }
object IssueOutline extends Table[(String, String, Int, Int)]("ISSUE_OUTLINE_VIEW") with IssueTemplate {
def commentCount = column[Int]("COMMENT_COUNT")
def * = userName ~ repositoryName ~ issueId ~ commentCount
}
object Issues extends Table[Issue]("ISSUE") with IssueTemplate with MilestoneTemplate { object Issues extends Table[Issue]("ISSUE") with IssueTemplate with MilestoneTemplate {
def openedUserName = column[String]("OPENED_USER_NAME") def openedUserName = column[String]("OPENED_USER_NAME")
def assignedUserName = column[String]("ASSIGNED_USER_NAME") def assignedUserName = column[String]("ASSIGNED_USER_NAME")

View File

@@ -99,19 +99,19 @@ trait IssuesService {
def searchIssue(owner: String, repository: String, condition: IssueSearchCondition, def searchIssue(owner: String, repository: String, condition: IssueSearchCondition,
filter: String, userName: Option[String], offset: Int, limit: Int): List[(Issue, List[Label], Int)] = { filter: String, userName: Option[String], offset: Int, limit: Int): List[(Issue, List[Label], Int)] = {
// get issues and comment count // get issues and comment count and labels
val issues = searchIssueQuery(owner, repository, condition, filter, userName) searchIssueQuery(owner, repository, condition, filter, userName)
.leftJoin(Query(IssueComments) .innerJoin(IssueOutline).on { (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) }
.filter { t => .leftJoin (IssueLabels) .on { case ((t1, t2), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) }
(t.byRepository(owner, repository)) && .leftJoin (Labels) .on { case (((t1, t2), t3), t4) => t3.byLabel(t4.userName, t4.repositoryName, t4.labelId) }
(t.action inSetBind Seq("comment", "close_comment", "reopen_comment")) .map { case (((t1, t2), t3), t4) =>
(t1, t2.commentCount, t4.labelId.?, t4.labelName.?, t4.color.?)
} }
.groupBy { _.issueId } .sortBy(_._4) // labelName
.map { case (issueId, t) => issueId ~ t.length }).on((t1, t2) => t1.issueId is t2._1) .sortBy { case (t1, commentCount, _,_,_) =>
.sortBy { case (t1, t2) =>
(condition.sort match { (condition.sort match {
case "created" => t1.registeredDate case "created" => t1.registeredDate
case "comments" => t2._2 case "comments" => commentCount
case "updated" => t1.updatedDate case "updated" => t1.updatedDate
}) match { }) match {
case sort => condition.direction match { case sort => condition.direction match {
@@ -120,26 +120,17 @@ trait IssuesService {
} }
} }
} }
.map { case (t1, t2) => (t1, t2._2.ifNull(0)) }
.drop(offset).take(limit) .drop(offset).take(limit)
.list .list
.splitWith(_._1.issueId == _._1.issueId)
// get labels .map { issues => issues.head match {
val labels = Query(IssueLabels) case (issue, commentCount, _,_,_) =>
.innerJoin(Labels).on { (t1, t2) => (issue,
t1.byLabel(t2.userName, t2.repositoryName, t2.labelId) issues.flatMap { t => t._3.map (
} Label(issue.userName, issue.repositoryName, _, t._4.get, t._5.get)
.filter { case (t1, t2) => )} toList,
(t1.byRepository(owner, repository)) && commentCount)
(t1.issueId inSetBind (issues.map(_._1.issueId))) }} toList
}
.sortBy { case (t1, t2) => t1.issueId ~ t2.labelName }
.map { case (t1, t2) => (t1.issueId, t2) }
.list
issues.map { case (issue, commentCount) =>
(issue, labels.collect { case (issueId, labels) if(issueId == issue.issueId) => labels }, commentCount)
}
} }
/** /**