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

Side by Side Diff: milo/appengine/buildbot/master.go

Issue 2668763002: Use a datastore batcher for build queries. (Closed)
Patch Set: Created 3 years, 10 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
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "compress/gzip" 9 "compress/gzip"
10 "encoding/json" 10 "encoding/json"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // User logged in, master found, master internal: nil 42 // User logged in, master found, master internal: nil
43 // User logged in, master not found: 404 43 // User logged in, master not found: 404
44 // User logged in, master found, master internal: 404 44 // User logged in, master found, master internal: 404
45 // Other error: 500 45 // Other error: 500
46 func checkAccess(c context.Context, err error, internal bool) error { 46 func checkAccess(c context.Context, err error, internal bool) error {
47 cu := auth.CurrentUser(c) 47 cu := auth.CurrentUser(c)
48 switch { 48 switch {
49 case err == ds.ErrNoSuchEntity: 49 case err == ds.ErrNoSuchEntity:
50 if cu.Identity == identity.AnonymousIdentity { 50 if cu.Identity == identity.AnonymousIdentity {
51 return errNotAuth 51 return errNotAuth
52 } else {
53 return errMasterNotFound
54 } 52 }
53 return errMasterNotFound
55 case err != nil: 54 case err != nil:
56 return err 55 return err
57 } 56 }
58 57
59 // Do the ACL check if the entry is internal. 58 // Do the ACL check if the entry is internal.
60 if internal { 59 if internal {
61 allowed, err := settings.IsAllowedInternal(c) 60 allowed, err := settings.IsAllowedInternal(c)
62 if err != nil { 61 if err != nil {
63 return err 62 return err
64 } 63 }
65 if !allowed { 64 if !allowed {
66 if cu.Identity == identity.AnonymousIdentity { 65 if cu.Identity == identity.AnonymousIdentity {
67 return errNotAuth 66 return errNotAuth
68 } else {
69 return errMasterNotFound
70 } 67 }
68 return errMasterNotFound
71 } 69 }
72 } 70 }
73 71
74 return nil 72 return nil
75 } 73 }
76 74
77 // getMasterEntry feches the named master and does an ACL check on the 75 // getMasterEntry feches the named master and does an ACL check on the
78 // current user. 76 // current user.
79 // It returns: 77 // It returns:
80 func getMasterEntry(c context.Context, name string) (*buildbotMasterEntry, error ) { 78 func getMasterEntry(c context.Context, name string) (*buildbotMasterEntry, error ) {
(...skipping 19 matching lines...) Expand all
100 } 98 }
101 99
102 // GetAllBuilders returns a resp.Module object containing all known masters 100 // GetAllBuilders returns a resp.Module object containing all known masters
103 // and builders. 101 // and builders.
104 func GetAllBuilders(c context.Context) (*resp.Module, error) { 102 func GetAllBuilders(c context.Context) (*resp.Module, error) {
105 result := &resp.Module{Name: "Buildbot"} 103 result := &resp.Module{Name: "Buildbot"}
106 // Fetch all Master entries from datastore 104 // Fetch all Master entries from datastore
107 q := ds.NewQuery("buildbotMasterEntry") 105 q := ds.NewQuery("buildbotMasterEntry")
108 // TODO(hinoka): Maybe don't look past like a month or so? 106 // TODO(hinoka): Maybe don't look past like a month or so?
109 entries := []*buildbotMasterEntry{} 107 entries := []*buildbotMasterEntry{}
110 » err := ds.GetAll(c, q, &entries) 108 » err := (&ds.Batcher{}).GetAll(c, q, &entries)
111 if err != nil { 109 if err != nil {
112 return nil, err 110 return nil, err
113 } 111 }
114 112
115 // Add each builder from each master entry into the result. 113 // Add each builder from each master entry into the result.
116 // TODO(hinoka): FanInOut this? 114 // TODO(hinoka): FanInOut this?
117 for _, entry := range entries { 115 for _, entry := range entries {
118 if entry.Internal { 116 if entry.Internal {
119 // Bypass the master if it's an internal master and the user is not 117 // Bypass the master if it's an internal master and the user is not
120 // part of the buildbot-private project. 118 // part of the buildbot-private project.
(...skipping 24 matching lines...) Expand all
145 Label: bn, 143 Label: bn,
146 // Go templates escapes this for us, and also 144 // Go templates escapes this for us, and also
147 // slashes are not allowed in builder names. 145 // slashes are not allowed in builder names.
148 URL: fmt.Sprintf("/buildbot/%s/%s", entry.Name, bn), 146 URL: fmt.Sprintf("/buildbot/%s/%s", entry.Name, bn),
149 }) 147 })
150 } 148 }
151 result.Masters = append(result.Masters, ml) 149 result.Masters = append(result.Masters, ml)
152 } 150 }
153 return result, nil 151 return result, nil
154 } 152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698