From af76d46b53b98a35190dca796ba76b12f2ba4a0b Mon Sep 17 00:00:00 2001 From: Jordan Brockopp Date: Fri, 2 Feb 2018 13:03:40 -0600 Subject: [PATCH] add page param for getting build list with offset --- store/datastore/builds.go | 6 +++--- store/datastore/builds_test.go | 2 +- store/store.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/store/datastore/builds.go b/store/datastore/builds.go index 6793fa02..fddee0b2 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 4aed2d32..69497f85 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 ccfd635f..88c6ccff 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) {