diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ecd23f..886e080 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: timeout-minutes: 20 strategy: matrix: - java: [8, 11] + java: [11] steps: - uses: actions/checkout@v3 - name: Cache diff --git a/.gitignore b/.gitignore index c92eacb..ae82060 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ lib_managed/ src_managed/ project/boot/ project/plugins/project/ +.bsp/ # Scala-IDE specific .scala_dependencies diff --git a/build.sbt b/build.sbt index 62ac8ab..4498917 100644 --- a/build.sbt +++ b/build.sbt @@ -5,6 +5,6 @@ scalaVersion := "2.13.10" gitbucketVersion := "4.39.0" scalacOptions := Seq("-deprecation", "-feature", "-language:postfixOps") -Compile / javacOptions ++= Seq("-target", "8", "-source", "8") +Compile / javacOptions ++= Seq("-target", "11", "-source", "11") useJCenter := true diff --git a/src/main/scala/gitbucket/gist/controller/GistController.scala b/src/main/scala/gitbucket/gist/controller/GistController.scala index 8988d32..10b2112 100644 --- a/src/main/scala/gitbucket/gist/controller/GistController.scala +++ b/src/main/scala/gitbucket/gist/controller/GistController.scala @@ -50,7 +50,7 @@ trait GistControllerBase extends ControllerBase { case s => s.toInt } val result = getVisibleGists((page - 1) * Limit, Limit, context.loginAccount) - val count = countPublicGists() + val count = countVisibleGists(context.loginAccount) val gists: Seq[(Gist, GistInfo)] = result.map { gist => val userName = gist.userName diff --git a/src/main/scala/gitbucket/gist/service/GistService.scala b/src/main/scala/gitbucket/gist/service/GistService.scala index e7e0b0b..5ef7229 100644 --- a/src/main/scala/gitbucket/gist/service/GistService.scala +++ b/src/main/scala/gitbucket/gist/service/GistService.scala @@ -9,35 +9,34 @@ import gitbucket.gist.model.Profile.dateColumnType trait GistService { - def getRecentGists(userName: String, offset: Int, limit: Int)(implicit s: Session): Seq[Gist] = - Gists.filter(_.userName === userName.bind).sortBy(_.registeredDate desc).drop(offset).take(limit).list + def getVisibleGists(offset: Int, limit: Int, account: Option[Account])(implicit s: Session): Seq[Gist] = + visibleHistsQuery(account).sortBy(_.registeredDate desc).drop(offset).take(limit).list - def getVisibleGists(offset: Int, limit: Int, account: Option[Account])(implicit s: Session): Seq[Gist] = { - val query = account.map { x => + def countVisibleGists(account: Option[Account])(implicit s: Session): Int = + Query(visibleHistsQuery(account).length).first + + private def visibleHistsQuery(account: Option[Account]): Query[Gists, Gists#TableElementType, Seq] = { + account.map { x => Gists.filter { t => (t.mode === "PUBLIC".bind) || (t.userName === x.userName.bind) } } getOrElse { Gists.filter { t => (t.mode === "PUBLIC".bind) } } - query.sortBy(_.registeredDate desc).drop(offset).take(limit).list } - def countPublicGists()(implicit s: Session): Int = - Query(Gists.filter(_.mode === "PUBLIC".bind).length).first - def getUserGists(userName: String, loginUserName: Option[String], offset: Int, limit: Int)(implicit s: Session): Seq[Gist] = - (if(loginUserName.isDefined){ - Gists filter(t => (t.userName === userName.bind) && ((t.userName === loginUserName.bind) || (t.mode === "PUBLIC".bind))) - } else { - Gists filter(t => (t.userName === userName.bind) && (t.mode === "PUBLIC".bind)) - }).sortBy(_.registeredDate desc).drop(offset).take(limit).list + userGistsQuery(userName, loginUserName).sortBy(_.registeredDate desc).drop(offset).take(limit).list def countUserGists(userName: String, loginUserName: Option[String])(implicit s: Session): Int = - Query((if(loginUserName.isDefined){ - Gists.filter(t => (t.userName === userName.bind) && ((t.userName === loginUserName.bind) || (t.mode === "PUBLIC".bind))) + Query(userGistsQuery(userName, loginUserName).length).first + + private def userGistsQuery(userName: String, loginUserName: Option[String]): Query[Gists, Gists#TableElementType, Seq] = { + if (loginUserName.isDefined) { + Gists filter (t => (t.userName === userName.bind) && ((t.userName === loginUserName.bind) || (t.mode === "PUBLIC".bind))) } else { - Gists.filter(t => (t.userName === userName.bind) && (t.mode === "PUBLIC".bind)) - }).length).first + Gists filter (t => (t.userName === userName.bind) && (t.mode === "PUBLIC".bind)) + } + } def getGist(userName: String, repositoryName: String)(implicit s: Session): Option[Gist] = Gists.filter(t => (t.userName === userName.bind) && (t.repositoryName === repositoryName.bind)).firstOption