mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 11:36:05 +01:00
(refs #121)Optimize push performance for a lot of commit.
This commit is contained in:
@@ -141,7 +141,13 @@ trait ActivityService {
|
|||||||
def insertCommitId(userName: String, repositoryName: String, commitId: String) = {
|
def insertCommitId(userName: String, repositoryName: String, commitId: String) = {
|
||||||
CommitLog insert (userName, repositoryName, commitId)
|
CommitLog insert (userName, repositoryName, commitId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def insertAllCommitIds(userName: String, repositoryName: String, commitIds: List[String]) =
|
||||||
|
CommitLog insertAll (commitIds.map(commitId => (userName, repositoryName, commitId)): _*)
|
||||||
|
|
||||||
|
def getAllCommitIds(userName: String, repositoryName: String): List[String] =
|
||||||
|
Query(CommitLog).filter(_.byRepository(userName, repositoryName)).map(_.commitId).list
|
||||||
|
|
||||||
def existsCommitId(userName: String, repositoryName: String, commitId: String): Boolean =
|
def existsCommitId(userName: String, repositoryName: String, commitId: String): Boolean =
|
||||||
Query(CommitLog).filter(_.byPrimaryKey(userName, repositoryName, commitId)).firstOption.isDefined
|
Query(CommitLog).filter(_.byPrimaryKey(userName, repositoryName, commitId)).firstOption.isDefined
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import util.Implicits._
|
|||||||
import service._
|
import service._
|
||||||
import WebHookService._
|
import WebHookService._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
import util.JGitUtil.CommitInfo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides Git repository via HTTP.
|
* Provides Git repository via HTTP.
|
||||||
@@ -87,19 +88,26 @@ class CommitLogHook(owner: String, repository: String, userName: String, baseURL
|
|||||||
val commits = JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name)
|
val commits = JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name)
|
||||||
val refName = command.getRefName.split("/")
|
val refName = command.getRefName.split("/")
|
||||||
|
|
||||||
// apply issue comment
|
// Extract new commit and apply issue comment
|
||||||
val newCommits = commits.flatMap { commit =>
|
val newCommits = if(commits.size > 1000){
|
||||||
if(!existsCommitId(owner, repository, commit.id)){
|
val existIds = getAllCommitIds(owner, repository)
|
||||||
insertCommitId(owner, repository, commit.id)
|
commits.flatMap { commit =>
|
||||||
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData =>
|
optionIf(!existIds.contains(commit.id)){
|
||||||
val issueId = matchData.group(2)
|
createIssueComment(commit)
|
||||||
if(getAccountByUserName(commit.committer).isDefined && getIssue(owner, repository, issueId).isDefined){
|
Some(commit)
|
||||||
createComment(owner, repository, commit.committer, issueId.toInt, commit.fullMessage, "commit")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some(commit)
|
}
|
||||||
} else None
|
} else {
|
||||||
}.toList
|
commits.flatMap { commit =>
|
||||||
|
optionIf(!existsCommitId(owner, repository, commit.id)){
|
||||||
|
createIssueComment(commit)
|
||||||
|
Some(commit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// batch insert all new commit id
|
||||||
|
insertAllCommitIds(owner, repository, newCommits.map(_.id))
|
||||||
|
|
||||||
// record activity
|
// record activity
|
||||||
if(refName(1) == "heads"){
|
if(refName(1) == "heads"){
|
||||||
@@ -132,4 +140,14 @@ class CommitLogHook(owner: String, repository: String, userName: String, baseURL
|
|||||||
// update repository last modified time.
|
// update repository last modified time.
|
||||||
updateLastActivityDate(owner, repository)
|
updateLastActivityDate(owner, repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def createIssueComment(commit: CommitInfo) = {
|
||||||
|
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData =>
|
||||||
|
val issueId = matchData.group(2)
|
||||||
|
if(getAccountByUserName(commit.committer).isDefined && getIssue(owner, repository, issueId).isDefined){
|
||||||
|
createComment(owner, repository, commit.committer, issueId.toInt, commit.fullMessage, "commit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user