diff --git a/server/badge.go b/server/badge.go index ed3947de8..455bd90a9 100644 --- a/server/badge.go +++ b/server/badge.go @@ -72,7 +72,7 @@ func GetCC(c *gin.Context) { return } - builds, err := store.GetBuildList(c, repo) + builds, err := store.GetBuildList(c, repo, 1) if err != nil || len(builds) == 0 { c.AbortWithStatus(404) return diff --git a/server/build.go b/server/build.go index a9518844c..c66807d6a 100644 --- a/server/build.go +++ b/server/build.go @@ -25,7 +25,13 @@ import ( func GetBuilds(c *gin.Context) { repo := session.Repo(c) - builds, err := store.GetBuildList(c, repo) + page, err := strconv.Atoi(c.DefaultQuery("page", "1")) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + return + } + + builds, err := store.GetBuildList(c, repo, page) if err != nil { c.AbortWithStatus(http.StatusInternalServerError) return diff --git a/store/datastore/builds.go b/store/datastore/builds.go index 6793fa027..fddee0b25 100644 --- a/store/datastore/builds.go +++ b/store/datastore/builds.go @@ -45,9 +45,9 @@ func (db *datastore) GetBuildLastBefore(repo *model.Repo, branch string, num int return build, err } -func (db *datastore) GetBuildList(repo *model.Repo) ([]*model.Build, error) { +func (db *datastore) GetBuildList(repo *model.Repo, page int) ([]*model.Build, error) { var builds = []*model.Build{} - var err = meddler.QueryAll(db, &builds, rebind(buildListQuery), repo.ID) + var err = meddler.QueryAll(db, &builds, rebind(buildListQuery), repo.ID, 50*(page-1)) return builds, err } @@ -130,7 +130,7 @@ SELECT * FROM builds WHERE build_repo_id = ? ORDER BY build_number DESC -LIMIT 50 +LIMIT 50 OFFSET ? ` const buildNumberQuery = ` diff --git a/store/datastore/builds_test.go b/store/datastore/builds_test.go index 4aed2d326..69497f85f 100644 --- a/store/datastore/builds_test.go +++ b/store/datastore/builds_test.go @@ -247,7 +247,7 @@ func TestBuilds(t *testing.T) { } s.CreateBuild(build1, []*model.Proc{}...) s.CreateBuild(build2, []*model.Proc{}...) - builds, err := s.GetBuildList(&model.Repo{ID: 1}) + builds, err := s.GetBuildList(&model.Repo{ID: 1}, 1) g.Assert(err == nil).IsTrue() g.Assert(len(builds)).Equal(2) g.Assert(builds[0].ID).Equal(build2.ID) diff --git a/store/store.go b/store/store.go index ccfd635fe..88c6ccff2 100644 --- a/store/store.go +++ b/store/store.go @@ -67,7 +67,7 @@ type Store interface { GetBuildLastBefore(*model.Repo, string, int64) (*model.Build, error) // GetBuildList gets a list of builds for the repository - GetBuildList(*model.Repo) ([]*model.Build, error) + GetBuildList(*model.Repo, int) ([]*model.Build, error) // GetBuildQueue gets a list of build in queue. GetBuildQueue() ([]*model.Feed, error) @@ -223,8 +223,8 @@ func GetBuildLastBefore(c context.Context, repo *model.Repo, branch string, numb return FromContext(c).GetBuildLastBefore(repo, branch, number) } -func GetBuildList(c context.Context, repo *model.Repo) ([]*model.Build, error) { - return FromContext(c).GetBuildList(repo) +func GetBuildList(c context.Context, repo *model.Repo, page int) ([]*model.Build, error) { + return FromContext(c).GetBuildList(repo, page) } func GetBuildQueue(c context.Context) ([]*model.Feed, error) {