mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
Fix the inefficient query.
This commit is contained in:
@@ -24,7 +24,7 @@ trait AccountService {
|
|||||||
lastLoginDate = None)
|
lastLoginDate = None)
|
||||||
|
|
||||||
def updateAccount(account: Account): Unit =
|
def updateAccount(account: Account): Unit =
|
||||||
Query(Accounts)
|
Accounts
|
||||||
.filter { a => a.userName is account.userName.bind }
|
.filter { a => a.userName is account.userName.bind }
|
||||||
.map { a => a.password ~ a.mailAddress ~ a.isAdmin ~ a.url.? ~ a.registeredDate ~ a.updatedDate ~ a.lastLoginDate.? }
|
.map { a => a.password ~ a.mailAddress ~ a.isAdmin ~ a.url.? ~ a.registeredDate ~ a.updatedDate ~ a.lastLoginDate.? }
|
||||||
.update (
|
.update (
|
||||||
@@ -37,6 +37,6 @@ trait AccountService {
|
|||||||
account.lastLoginDate)
|
account.lastLoginDate)
|
||||||
|
|
||||||
def updateLastLoginDate(userName: String): Unit =
|
def updateLastLoginDate(userName: String): Unit =
|
||||||
Query(Accounts).filter(_.userName is userName.bind).map(_.lastLoginDate).update(currentDate)
|
Accounts.filter(_.userName is userName.bind).map(_.lastLoginDate).update(currentDate)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ trait IssuesService {
|
|||||||
.map { case (labelName, t) =>
|
.map { case (labelName, t) =>
|
||||||
labelName ~ t.length
|
labelName ~ t.length
|
||||||
}
|
}
|
||||||
.list
|
|
||||||
.toMap
|
.toMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ trait LabelsService {
|
|||||||
Labels.ins insert (owner, repository, labelName, color)
|
Labels.ins insert (owner, repository, labelName, color)
|
||||||
|
|
||||||
def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String): Unit =
|
def updateLabel(owner: String, repository: String, labelId: Int, labelName: String, color: String): Unit =
|
||||||
Query(Labels).filter(_.byPrimaryKey(owner, repository, labelId)).map(t => t.labelName ~ t.color)
|
Labels.filter(_.byPrimaryKey(owner, repository, labelId)).map(t => t.labelName ~ t.color)
|
||||||
.update(labelName, color)
|
.update(labelName, color)
|
||||||
|
|
||||||
def deleteLabel(owner: String, repository: String, labelId: Int): Unit = {
|
def deleteLabel(owner: String, repository: String, labelId: Int): Unit = {
|
||||||
Query(IssueLabels).filter(_.byLabel(owner, repository, labelId)).delete
|
IssueLabels.filter(_.byLabel(owner, repository, labelId)).delete
|
||||||
Query(Labels).filter(_.byPrimaryKey(owner, repository, labelId)).delete
|
Labels.filter(_.byPrimaryKey(owner, repository, labelId)).delete
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ trait MilestonesService {
|
|||||||
Milestones.ins insert (owner, repository, title, description, dueDate, None)
|
Milestones.ins insert (owner, repository, title, description, dueDate, None)
|
||||||
|
|
||||||
def updateMilestone(milestone: Milestone): Unit =
|
def updateMilestone(milestone: Milestone): Unit =
|
||||||
Query(Milestones)
|
Milestones
|
||||||
.filter (t => t.byPrimaryKey(milestone.userName, milestone.repositoryName, milestone.milestoneId))
|
.filter (t => t.byPrimaryKey(milestone.userName, milestone.repositoryName, milestone.milestoneId))
|
||||||
.map (t => t.title ~ t.description.? ~ t.dueDate.? ~ t.closedDate.?)
|
.map (t => t.title ~ t.description.? ~ t.dueDate.? ~ t.closedDate.?)
|
||||||
.update (milestone.title, milestone.description, milestone.dueDate, milestone.closedDate)
|
.update (milestone.title, milestone.description, milestone.dueDate, milestone.closedDate)
|
||||||
@@ -23,8 +23,8 @@ trait MilestonesService {
|
|||||||
def closeMilestone(milestone: Milestone): Unit = updateMilestone(milestone.copy(closedDate = Some(currentDate)))
|
def closeMilestone(milestone: Milestone): Unit = updateMilestone(milestone.copy(closedDate = Some(currentDate)))
|
||||||
|
|
||||||
def deleteMilestone(owner: String, repository: String, milestoneId: Int): Unit = {
|
def deleteMilestone(owner: String, repository: String, milestoneId: Int): Unit = {
|
||||||
Query(Issues).filter(_.byMilestone(owner, repository, milestoneId)).map(_.milestoneId.?).update(None)
|
Issues.filter(_.byMilestone(owner, repository, milestoneId)).map(_.milestoneId.?).update(None)
|
||||||
Query(Milestones).filter(_.byPrimaryKey(owner, repository, milestoneId)).delete
|
Milestones.filter(_.byPrimaryKey(owner, repository, milestoneId)).delete
|
||||||
}
|
}
|
||||||
|
|
||||||
def getMilestone(owner: String, repository: String, milestoneId: Int): Option[Milestone] =
|
def getMilestone(owner: String, repository: String, milestoneId: Int): Option[Milestone] =
|
||||||
@@ -34,9 +34,7 @@ trait MilestonesService {
|
|||||||
val counts = Issues
|
val counts = Issues
|
||||||
.filter { t => (t.byRepository(owner, repository)) && (t.milestoneId isNotNull) }
|
.filter { t => (t.byRepository(owner, repository)) && (t.milestoneId isNotNull) }
|
||||||
.groupBy { t => t.milestoneId ~ t.closed }
|
.groupBy { t => t.milestoneId ~ t.closed }
|
||||||
.map { case (t1, t2) => t1._1 ~ t1._2 ~ t2.length }
|
.map { case (t1, t2) => (t1._1 ~ t1._2) -> t2.length }
|
||||||
.list
|
|
||||||
.map { case (milestoneId, closed, count) => (milestoneId, closed) -> count }
|
|
||||||
.toMap
|
.toMap
|
||||||
|
|
||||||
getMilestones(owner, repository).map { milestone =>
|
getMilestones(owner, repository).map { milestone =>
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* @return the list of repository names
|
* @return the list of repository names
|
||||||
*/
|
*/
|
||||||
def getRepositoryNamesOfUser(userName: String): List[String] =
|
def getRepositoryNamesOfUser(userName: String): List[String] =
|
||||||
Query(Repositories).filter(_.userName is userName.bind).list.map(_.repositoryName)
|
Query(Repositories) filter(_.userName is userName.bind) map (_.repositoryName) list
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of specified user's repositories information.
|
* Returns the list of specified user's repositories information.
|
||||||
@@ -141,14 +141,14 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* Updates the last activity date of the repository.
|
* Updates the last activity date of the repository.
|
||||||
*/
|
*/
|
||||||
def updateLastActivityDate(userName: String, repositoryName: String): Unit =
|
def updateLastActivityDate(userName: String, repositoryName: String): Unit =
|
||||||
Query(Repositories).filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).update(currentDate)
|
Repositories.filter(_.byRepository(userName, repositoryName)).map(_.lastActivityDate).update(currentDate)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save repository options.
|
* Save repository options.
|
||||||
*/
|
*/
|
||||||
def saveRepositoryOptions(userName: String, repositoryName: String,
|
def saveRepositoryOptions(userName: String, repositoryName: String,
|
||||||
description: Option[String], defaultBranch: String, isPrivate: Boolean): Unit =
|
description: Option[String], defaultBranch: String, isPrivate: Boolean): Unit =
|
||||||
Query(Repositories).filter(_.byRepository(userName, repositoryName))
|
Repositories.filter(_.byRepository(userName, repositoryName))
|
||||||
.map { r => r.description.? ~ r.defaultBranch ~ r.isPrivate ~ r.updatedDate }
|
.map { r => r.description.? ~ r.defaultBranch ~ r.isPrivate ~ r.updatedDate }
|
||||||
.update (description, defaultBranch, isPrivate, currentDate)
|
.update (description, defaultBranch, isPrivate, currentDate)
|
||||||
|
|
||||||
@@ -170,8 +170,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* @param collaboratorName the collaborator name
|
* @param collaboratorName the collaborator name
|
||||||
*/
|
*/
|
||||||
def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String): Unit =
|
def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String): Unit =
|
||||||
Query(Collaborators).filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).delete
|
Collaborators.filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).delete
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of collaborators name which is sorted with ascending order.
|
* Returns the list of collaborators name which is sorted with ascending order.
|
||||||
@@ -181,7 +180,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* @return the list of collaborators name
|
* @return the list of collaborators name
|
||||||
*/
|
*/
|
||||||
def getCollaborators(userName: String, repositoryName: String): List[String] =
|
def getCollaborators(userName: String, repositoryName: String): List[String] =
|
||||||
Query(Collaborators).filter(_.byRepository(userName, repositoryName)).sortBy(_.collaboratorName).list.map(_.collaboratorName)
|
Query(Collaborators).filter(_.byRepository(userName, repositoryName)).sortBy(_.collaboratorName).map(_.collaboratorName).list
|
||||||
|
|
||||||
def hasWritePermission(owner: String, repository: String, loginAccount: Option[Account]): Boolean = {
|
def hasWritePermission(owner: String, repository: String, loginAccount: Option[Account]): Boolean = {
|
||||||
loginAccount match {
|
loginAccount match {
|
||||||
|
|||||||
Reference in New Issue
Block a user