OLD | NEW |
1 // Copyright 2016 The LUCI Authors. | 1 // Copyright 2016 The LUCI Authors. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 return &datastore.Batcher{ | 38 return &datastore.Batcher{ |
39 Size: constraints.QueryBatchSize, | 39 Size: constraints.QueryBatchSize, |
40 } | 40 } |
41 } | 41 } |
42 | 42 |
43 // runBuildsQuery takes a buildbotBuild query and returns a list of builds | 43 // runBuildsQuery takes a buildbotBuild query and returns a list of builds |
44 // along with a cursor. We pass the limit here and apply it to the query as | 44 // along with a cursor. We pass the limit here and apply it to the query as |
45 // an optimization because then we can create a build container of that size. | 45 // an optimization because then we can create a build container of that size. |
46 func runBuildsQuery(c context.Context, q *datastore.Query, limit int32) ( | 46 func runBuildsQuery(c context.Context, q *datastore.Query, limit int32) ( |
47 » []*buildbotBuild, *datastore.Cursor, error) { | 47 » []*buildbotBuild, datastore.Cursor, error) { |
48 | 48 |
49 if limit != 0 { | 49 if limit != 0 { |
50 q = q.Limit(limit) | 50 q = q.Limit(limit) |
51 } | 51 } |
52 builds := make([]*buildbotBuild, 0, limit) | 52 builds := make([]*buildbotBuild, 0, limit) |
53 » var nextCursor *datastore.Cursor | 53 » var nextCursor datastore.Cursor |
54 err := getBuildQueryBatcher(c).Run( | 54 err := getBuildQueryBatcher(c).Run( |
55 c, q, func(build *buildbotBuild, getCursor datastore.CursorCB) e
rror { | 55 c, q, func(build *buildbotBuild, getCursor datastore.CursorCB) e
rror { |
56 builds = append(builds, build) | 56 builds = append(builds, build) |
57 tmpCursor, err := getCursor() | 57 tmpCursor, err := getCursor() |
58 if err != nil { | 58 if err != nil { |
59 return err | 59 return err |
60 } | 60 } |
61 » » » nextCursor = &tmpCursor | 61 » » » nextCursor = tmpCursor |
62 return nil | 62 return nil |
63 }) | 63 }) |
64 return builds, nextCursor, err | 64 return builds, nextCursor, err |
65 } | 65 } |
OLD | NEW |