mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +01:00
Improve update pull request query
commitIdFrom and commitIdTo columns update by one query.
This commit is contained in:
@@ -3,7 +3,6 @@ package service
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
import Database.threadLocalSession
|
||||
import model._
|
||||
import util.ControlUtil._
|
||||
|
||||
trait PullRequestService { self: IssuesService =>
|
||||
import PullRequestService._
|
||||
@@ -15,11 +14,10 @@ trait PullRequestService { self: IssuesService =>
|
||||
}
|
||||
}
|
||||
|
||||
def updateCommitIdTo(owner: String, repository: String, issueId: Int, commitIdTo: String): Unit =
|
||||
Query(PullRequests).filter(_.byPrimaryKey(owner, repository, issueId)).map(_.commitIdTo).update(commitIdTo)
|
||||
|
||||
def updateCommitIdFrom(owner: String, repository: String, issueId: Int, commitIdFrom: String): Unit =
|
||||
Query(PullRequests).filter(_.byPrimaryKey(owner, repository, issueId)).map(_.commitIdFrom).update(commitIdFrom)
|
||||
def updateCommitId(owner: String, repository: String, issueId: Int, commitIdTo: String, commitIdFrom: String): Unit =
|
||||
Query(PullRequests).filter(_.byPrimaryKey(owner, repository, issueId))
|
||||
.map(pr => pr.commitIdTo ~ pr.commitIdFrom)
|
||||
.update((commitIdTo, commitIdFrom))
|
||||
|
||||
def getPullRequestCountGroupByUser(closed: Boolean, owner: String, repository: Option[String]): List[PullRequestCount] =
|
||||
Query(PullRequests)
|
||||
|
||||
@@ -226,13 +226,10 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
||||
.call
|
||||
|
||||
val commitIdTo = oldGit.getRepository.resolve(s"refs/pull/${pullreq.issueId}/head").getName
|
||||
updateCommitIdTo(pullreq.userName, pullreq.repositoryName, pullreq.issueId, commitIdTo)
|
||||
|
||||
val commitIdFrom = JGitUtil.getForkedCommitId(oldGit, newGit,
|
||||
pullreq.userName, pullreq.repositoryName, pullreq.branch,
|
||||
pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch)
|
||||
// TODO(tanacasino): commitIdFrom and commitIdTo should be updated by one query...
|
||||
updateCommitIdFrom(pullreq.userName, pullreq.repositoryName, pullreq.issueId, commitIdFrom)
|
||||
updateCommitId(pullreq.userName, pullreq.repositoryName, pullreq.issueId, commitIdTo, commitIdFrom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user