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

Side by Side Diff: milo/buildsource/console.go

Issue 2978293002: [milo] Add an (uncached) method to get console rows. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « no previous file | milo/common/model/build_summary.go » ('j') | milo/common/model/build_summary.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The LUCI Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package buildsource
16
17 import (
18 "encoding/hex"
19
20 "golang.org/x/net/context"
21
22 ds "github.com/luci/gae/service/datastore"
Ryan Tseng 2017/07/19 08:07:57 nit: "datastore" is preferred in Milo
iannucci 2017/07/20 00:14:56 Done.
23
24 "github.com/luci/luci-go/common/data/stringset"
25 "github.com/luci/luci-go/common/errors"
26 "github.com/luci/luci-go/common/sync/parallel"
27
28 "github.com/luci/luci-go/milo/api/config"
29 "github.com/luci/luci-go/milo/common/model"
30 )
31
32 // GetBuildSummariesForConsole returns a row-oriented collection of BuildSummary
33 // objects. Each row corresponds to the similarly-indexed commit in the
34 // `commits` slice.
Ryan Tseng 2017/07/19 08:07:57 "row-oriented" could be little ambiguous. Should
iannucci 2017/07/20 00:14:56 Done.
35 func GetBuildSummariesForConsole(c context.Context, project string, console *con fig.Console, commits, builders []string) ([][]*model.BuildSummary, error) {
36 rawCommits := make([][]byte, len(commits))
37 for i, c := range commits {
38 var err error
Ryan Tseng 2017/07/19 08:07:57 nit: this can be inlined
iannucci 2017/07/20 00:14:56 can't because we're assigning to rawCommits[i]
39 if rawCommits[i], err = hex.DecodeString(c); err != nil {
40 return nil, errors.Annotate(err, "bad commit[%d]: %q", i , c).Err()
41 }
42 }
43
44 builderSet := stringset.NewFromSlice(builders...)
45
46 ret := make([][]*model.BuildSummary, len(commits))
Ryan Tseng 2017/07/19 08:07:58 might as well pre-allocate the whole matrix here
iannucci 2017/07/20 00:14:56 Acknowledged.
47 url := console.RepoURL
48 // HACK(iannucci): This little hack should be removed when console defin itions
49 // no longer use a manifest name of "REVISION". REVISION was used to ind ex the
50 // 'got_revision' value before manifests were implemented.
51 if console.ManifestName == "REVISION" {
52 url = ""
53 }
54 prefix := model.BuildSummaryPrefix(project, console.Name, console.Manife stName, url)
55 q := ds.NewQuery("BuildSummary").KeysOnly(true)
56 err := parallel.WorkPool(4, func(ch chan<- func() error) {
57 for i := range rawCommits {
58 i := i
59 ch <- func() error {
60 fullQ := q.Eq("ManifestRevisionIndex", prefix.Ad dRevision(rawCommits[i]))
61 return ds.Run(c, fullQ, func(bs *model.BuildSumm ary) {
62 if builderSet.Has(bs.BuilderID) {
63 ret[i] = append(ret[i], bs)
Ryan Tseng 2017/07/19 08:07:58 Pretty sure this is going to get mis-aligned. The
iannucci 2017/07/20 00:14:56 Acknowledged.
64 }
65 })
66 }
67 }
68 })
69
70 return ret, err
71 }
OLDNEW
« no previous file with comments | « no previous file | milo/common/model/build_summary.go » ('j') | milo/common/model/build_summary.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698