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

Side by Side Diff: milo/appengine/job_source/buildbot/datastore.go

Issue 2949783002: [milo] appengine/* -> * (Closed)
Patch Set: rebase Created 3 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package buildbot
6
7 import (
8 "github.com/luci/gae/service/datastore"
9
10 "golang.org/x/net/context"
11 )
12
13 // buildQueryBatchSize is the batch size to use when querying build. It is
14 // employed as an upper bound by getBuildQueryBatcher.
15 //
16 // This should be tuned to the observed query timeout for build loading. Since
17 // loading is CPU-bound, this will probably be low. If build queries start
18 // encountering datastore timeouts, reduce this value.
19 const buildQueryBatchSize = 50
20
21 // getBuildQueryBatcher returns a datastore.Batcher tuned for executing queries on the
22 // "buildbotBuild" entity.
23 func getBuildQueryBatcher(c context.Context) *datastore.Batcher {
24 constraints := datastore.Raw(c).Constraints()
25 if constraints.QueryBatchSize > buildQueryBatchSize {
26 constraints.QueryBatchSize = buildQueryBatchSize
27 }
28 return &datastore.Batcher{
29 Size: constraints.QueryBatchSize,
30 }
31 }
32
33 // runBuildsQuery takes a buildbotBuild query and returns a list of builds
34 // along with a cursor. We pass the limit here and apply it to the query as
35 // an optimization because then we can create a build container of that size.
36 func runBuildsQuery(c context.Context, q *datastore.Query, limit int32) (
37 []*buildbotBuild, *datastore.Cursor, error) {
38
39 if limit != 0 {
40 q = q.Limit(limit)
41 }
42 builds := make([]*buildbotBuild, 0, limit)
43 var nextCursor *datastore.Cursor
44 err := getBuildQueryBatcher(c).Run(
45 c, q, func(build *buildbotBuild, getCursor datastore.CursorCB) e rror {
46 builds = append(builds, build)
47 tmpCursor, err := getCursor()
48 if err != nil {
49 return err
50 }
51 nextCursor = &tmpCursor
52 return nil
53 })
54 return builds, nextCursor, err
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698