Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Unified Diff: milo/appengine/buildbot/datastore.go

Issue 2810113002: Milo buildbot builder page: Add pagnation with cursors. (Closed)
Patch Set: train Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/appengine/buildbot/console.go ('k') | milo/appengine/buildbot/grpc.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/buildbot/datastore.go
diff --git a/milo/appengine/buildbot/datastore.go b/milo/appengine/buildbot/datastore.go
index cef6ec9429be69fcb6b15535d22d227167e78565..cb45a4e7fd1a2c983e1c549c366ae6cd287da3e3 100644
--- a/milo/appengine/buildbot/datastore.go
+++ b/milo/appengine/buildbot/datastore.go
@@ -5,7 +5,7 @@
package buildbot
import (
- ds "github.com/luci/gae/service/datastore"
+ "github.com/luci/gae/service/datastore"
"golang.org/x/net/context"
)
@@ -18,14 +18,38 @@ import (
// encountering datastore timeouts, reduce this value.
const buildQueryBatchSize = 50
-// getBuildQueryBatcher returns a ds.Batcher tuned for executing queries on the
+// getBuildQueryBatcher returns a datastore.Batcher tuned for executing queries on the
// "buildbotBuild" entity.
-func getBuildQueryBatcher(c context.Context) *ds.Batcher {
- constraints := ds.Raw(c).Constraints()
+func getBuildQueryBatcher(c context.Context) *datastore.Batcher {
+ constraints := datastore.Raw(c).Constraints()
if constraints.QueryBatchSize > buildQueryBatchSize {
constraints.QueryBatchSize = buildQueryBatchSize
}
- return &ds.Batcher{
+ return &datastore.Batcher{
Size: constraints.QueryBatchSize,
}
}
+
+// runBuildsQuery takes a buildbotBuild query and returns a list of builds
+// along with a cursor. We pass the limit here and apply it to the query as
+// an optimization because then we can create a build container of that size.
+func runBuildsQuery(c context.Context, q *datastore.Query, limit int32) (
+ []*buildbotBuild, *datastore.Cursor, error) {
+
+ if limit != 0 {
+ q = q.Limit(limit)
+ }
+ builds := make([]*buildbotBuild, 0, limit)
+ var nextCursor *datastore.Cursor
+ err := getBuildQueryBatcher(c).Run(
+ c, q, func(build *buildbotBuild, getCursor datastore.CursorCB) error {
+ builds = append(builds, build)
+ tmpCursor, err := getCursor()
+ if err != nil {
+ return err
+ }
+ nextCursor = &tmpCursor
+ return nil
+ })
+ return builds, nextCursor, err
+}
« no previous file with comments | « milo/appengine/buildbot/console.go ('k') | milo/appengine/buildbot/grpc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698