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

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

Issue 2978293002: [milo] Add an (uncached) method to get console rows. (Closed)
Patch Set: make manifestkey its own type 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
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 "github.com/luci/gae/service/datastore"
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 // ConsoleRow is one row of a particular console.
33 //
34 // It has the git commit for the row, as well as a mapping of BuilderID to any
35 // BuildSummaries which reported using this commit.
36 type ConsoleRow struct {
37 Commit string
38 Builds map[BuilderID][]*model.BuildSummary
39 }
40
41 // GetConsoleRows returns a row-oriented collection of BuildSummary
42 // objects. Each row corresponds to the similarly-indexed commit in the
43 // `commits` slice.
44 func GetConsoleRows(c context.Context, project string, console *config.Console, commits, builders []string) ([]*ConsoleRow, error) {
45 rawCommits := make([][]byte, len(commits))
46 for i, c := range commits {
47 var err error
48 if rawCommits[i], err = hex.DecodeString(c); err != nil {
49 return nil, errors.Annotate(err, "bad commit[%d]: %q", i , c).Err()
50 }
51 }
52
53 builderSet := stringset.NewFromSlice(builders...)
54
55 ret := make([]*ConsoleRow, len(commits))
56 url := console.RepoURL
57 // HACK(iannucci): This little hack should be removed when console defin itions
58 // no longer use a manifest name of "REVISION". REVISION was used to ind ex the
59 // 'got_revision' value before manifests were implemented.
60 if console.ManifestName == "REVISION" {
61 url = ""
62 }
63 partialKey := model.NewPartialManifestKey(project, console.Name, console .ManifestName, url)
64 q := datastore.NewQuery("BuildSummary").KeysOnly(true)
65 err := parallel.WorkPool(4, func(ch chan<- func() error) {
66 for i := range rawCommits {
67 i := i
68 r := &ConsoleRow{Commit: commits[i]}
69 ret[i] = r
70 ch <- func() error {
71 fullQ := q.Eq("ManifestKey", partialKey.AddRevis ion(rawCommits[i]))
72 return datastore.Run(c, fullQ, func(bs *model.Bu ildSummary) {
73 if builderSet.Has(bs.BuilderID) {
74 bid := BuilderID(bs.BuilderID)
75 if r.Builds == nil {
76 r.Builds = map[BuilderID ][]*model.BuildSummary{}
77 }
78 r.Builds[bid] = append(r.Builds[ bid], bs)
79 }
80 })
81 }
82 }
83 })
84
85 return ret, err
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698